python linting and members #2206
-
Hi, I don't know a whole lot about python linting, but every tool I've tried has failed the following case:
I want the linter to tell me when references to non-existent members are found. This comes up when making changes to classes after code already references the pre-changed class, and I'm used to compilers being able to tell me where I need to update in other languages. Pylance has no problem with the above code, nor does mypy or other tools I've tried. In fact Pylance is ok with moving the code out of someFunction although mypy complains if the bad reference is in the main script scope. I assume the problem is because the linters are not branching into functions or something? But the whole point of linting, to me, or one of the points, is to assume that python classes are going to be assumed 'static' like in traditional typed languages - once I define the members, any non-defined member encountered should be considered an error? Is there a way to get the behavior I'm looking for? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
The term "linting" typically refers to tools that check for code style conformance (indentation, naming, etc.). By that definition, Pylance doesn't do any linting. For that, you can enable pylint or other tools specifically focused on code style. What you're looking for is static type checking, and Pylance does provide that. However, type checking errors are disabled by default in Pylance because many users don't want to be bothered by such errors. To enable this, set the "python.analysis.typeCheckingMode" setting to "basic". Once this mode is enabled, Pylance will emit errors or warnings for things like accesses to attributes that are not declared within a class. |
Beta Was this translation helpful? Give feedback.
-
oh ok, thanks for the reply! Do you work on Pylance? I have a lot of comments...
|
Beta Was this translation helpful? Give feedback.
The term "linting" typically refers to tools that check for code style conformance (indentation, naming, etc.). By that definition, Pylance doesn't do any linting. For that, you can enable pylint or other tools specifically focused on code style.
What you're looking for is static type checking, and Pylance does provide that. However, type checking errors are disabled by default in Pylance because many users don't want to be bothered by such errors. To enable this, set the "python.analysis.typeCheckingMode" setting to "basic". Once this mode is enabled, Pylance will emit errors or warnings for things like accesses to attributes that are not declared within a class.