rdtsc
rdtsc

Reputation: 1074

VS Code / Pylint: "third party import [x] should be placed before [y]"

Pylint likes to complain about the order of these imports:

from __future__ import print_function   # for improved print func
import logging, sys, configparser, datetime, pyodbc
from appJar import gui                  # testing GUI...

This results in:

C0411:third party import "from appJar import gui" should be placed before "import logging, sys, configparser, datetime, pyodbc"

However, no matter how these are rearranged, pylint always complains that something needs to come before something else. i.e,:

Example 2

from appJar import gui                  # testing GUI...
from __future__ import print_function   # for improved print func
import logging, sys, configparser, datetime, pyodbc

Results in:

C0411:standard import "from __future__ import print_function" should be placed before "from appJar import gui (50,1)" C0411:standard import "import logging, sys, configparser, datetime, pyodbc" should be placed before "from appJar import gui (51,1)" C0411:standard import "import logging, sys, configparser, datetime, pyodbc" should be placed before "from appJar import gui (51,1)" C0411:standard import "import logging, sys, configparser, datetime, pyodbc" should be placed before "from appJar import gui (51,1)" C0411:standard import "import logging, sys, configparser, datetime, pyodbc" should be placed before "from appJar import gui (51,1)"

Example 3

from __future__ import print_function   # for improved print func

from appJar import gui                  # testing GUI...

import logging, sys, configparser, datetime, pyodbc

Results in:

C0411:standard import "import logging, sys, configparser, datetime, pyodbc" should be placed before "from appJar import gui (53,1)" C0411:standard import "import logging, sys, configparser, datetime, pyodbc" should be placed before "from appJar import gui (53,1)" C0411:standard import "import logging, sys, configparser, datetime, pyodbc" should be placed before "from appJar import gui (53,1)" C0411:standard import "import logging, sys, configparser, datetime, pyodbc" should be placed before "from appJar import gui (53,1)"

Spacing doesn't seem to matter. Any ideas on how this should be written? Thank you.

Upvotes: 1

Views: 2838

Answers (1)

Jundiaius
Jundiaius

Reputation: 7718

The problem comes from the fact that this line:

import logging, sys, configparser, datetime, pyodbc

has imports from the standard Python lib (sys, logging, datetime...) and other from third-party libraries (pyodbc).

As standard imports should come before third party imports and third party imports should usually be in alphabetical order, this mix of standard and third party import in the same line is probably what is behind these errors.

Upvotes: 3

Related Questions