Enhancement: Allow specification of a list of modules to not do type checking for #5228
Replies: 19 comments
-
Are there any news regarding this feature? |
Beta Was this translation helpful? Give feedback.
-
There's a simple workaround that doesn't require any new settings or configuration knobs. You can create a type stub for the library that contains the following line: # thirdparty/__init__.pyi
def __getattr__(name: str) -> Any: ... # incomplete |
Beta Was this translation helpful? Give feedback.
-
Thanks for the suggestion! That is interesting, but if I understood correctly, it would not work well for groups working together in some repository, for example. It would require everyone to make that change separately, right? |
Beta Was this translation helpful? Give feedback.
-
You should add the stub to a top-level subdirectory called "typings" and check it in to your repo. Then everyone working on the project will benefit from it. If you would prefer some other directory name (like "stubs" or "type-stubs"), you can override the default name ("typings") using the "python.analysis.stubPath" setting. Or you can use the "stubPath" configuration key in the pyrightConfig.json file. |
Beta Was this translation helpful? Give feedback.
-
Nice, thanks again! I will try it out tomorrow. EDIT: Worked perfectly! |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
-
Without type information, the semantic highlighter doesn't know what semantics should be attributed to these symbols. That's the tradeoff. You have the following choices:
|
Beta Was this translation helpful? Give feedback.
-
@erictraut I think your are missing the point here. This is about third party libraries. Option (3) above is not developer friendly. There are MANY third party libraries out there. Most are not yet typed. We're asking for a feature that is equivalent to that |
Beta Was this translation helpful? Give feedback.
-
The option you're asking for is the equivalent of creating a stub library with a top-level |
Beta Was this translation helpful? Give feedback.
-
It is more of a burden!!! Adding a one line stub file means that you have to add separate files in your repo for each of the third party libraries that you use, rather than have one central options file that has the libraries you wish to ignore. Option 3 requires preparing stubs for a 3rd party library, (of which there are many in a typical project). That's a lot of work. |
Beta Was this translation helpful? Give feedback.
-
I guess that your definition of "burden" is different from mine. Creating a type stub file with one line doesn't strike me as a burden. It has the added benefit that you can optionally add additional type information to the file over time (incrementally moving toward option 3 when you see the benefits of doing so). This is how I manage my team's sizable Python code base, and it works well for us. |
Beta Was this translation helpful? Give feedback.
-
I can understand the benefits of option 3, but my impression is that the main benefits exist if you want to fill in (or correct) typing absences (or mistakes) of certain third party libraries. Option 3 is what I'll probably go with for now. But there would be a great benefit in a feature that could simply not show typing errors regarding a certain library while not interfering with the highlighting of VSCode. To give an example, traci has a method traci.trafficlight.getPhase(). The "trafficlight" there is a variable defined in the main file of the package, which accesses a private module _trafficlight and assigns trafficlight = _trafficlight.TrafficLightDomain(). When I create the stub, I must manually go and make this assignment on the main.pyi generated file. And I need this just to get the syntax highlight. This is a convoluted process since I don't want to change the typings of the library, not to mention that I need to understand the inner workings of traci. I just want the highlight and not seeing the errors that come from typing issues of this library. |
Beta Was this translation helpful? Give feedback.
-
And what I am telling you is that what would work well for us is to just have a list of libraries to ignore (and maintain the syntax highlighting, as @AloizioMacedo mentioned above). It also makes using I have a project that has 12 external libraries that we do So why can't you support both ways of doing it? |
Beta Was this translation helpful? Give feedback.
-
Semantic highlighting is based on the type information. They go hand-in-hand. You can't say "I want correct semantic highlight but I want to treat all of the symbols from this library as If we were to implement a configuration option to control this, it would have the same behavior as one-line stub files with a The one-line stub files work with mypy as well, so if you're looking for a solution that works across type checkers, it has that added benefit. |
Beta Was this translation helpful? Give feedback.
-
The compelling reason is ease of use. Surveyed my team and they all agree. |
Beta Was this translation helpful? Give feedback.
-
Couldn't the processes be separated? For example, a configuration for which for the purposes of semantic highlight, run the standard type checking as if there were no custom stub files created. And then pyright and the stub files would only act to raise errors/warnings, not interacting with the semantic highlight. Then your solutions with the stub files etc would work perfectly for me. |
Beta Was this translation helpful? Give feedback.
-
I suppose that's theoretically possible, but that would involve a completely different architecture than the one that pylance / pyright uses. It would also involve double the memory, double the processing, etc., so it's not really feasible. It would also mean that semantic highlighting information would no longer match that of the type checker, the hover text, the signature help, etc. I think that would be really confusing to have this mismatch. |
Beta Was this translation helpful? Give feedback.
-
I'm with @Dr-Irv here – it's a bit painful, and AFAICT we would need to create a So if we switch to pyright, we're going to have to use the less optimal setting |
Beta Was this translation helpful? Give feedback.
-
Converted this to a discussion item to see how many upvotes it might get. |
Beta Was this translation helpful? Give feedback.
-
I'm using a third party commercial library, and there are no type stubs provided by the third party. When using
mypy
, I can put something like this in mymypy.ini
file:where
thirdparty
is the name of the library. Then I knowmypy
won't complain about not finding stubs for that library.It would be useful to have an option in
pylance
that tells it to ignore specific libraries when you know there is no type stub available, and you know thatpython.analysis.useLibraryCodeForTypes
won't help, because the library is provided as apyd
file, so you can't look at the source.Beta Was this translation helpful? Give feedback.
All reactions