Closed mtomassoli closed 1 month ago
Yes, this is a bug. It's the same root cause as #7507 and #7369.
Possibly related.
PyLance now fails to interpret the generic type of this staticmethod
(arg is type[T]
) that is part of a generic class.
@no_type_check
@staticmethod
def it(
spec: type[T] | None = None,
*,
spec_set: bool = True,
...
I checked and the @no_type_check
decorator makes no difference on the result.
If I change to a brand new typevar the type hint changes to remove the Any but it still doesn't properly give the type.
Expected value is T | MegaMock
. Using T TypeVar which is used throughout the file, I get Any | MegaMock
. Using W
which I created just for this method, I get simply MegaMock
. Using PyLance 2024.5.1. PyRight is not explicitly installed.
TypeVar(T)
TypeVar(W)
You can see by the coloring it doesn't know what bar
is and doesn't provide it as an option for autocomplete. It does show all the MegaMock methods.
Library is MegaMock: https://github.com/JamesHutchison/megamock
@JamesHutchison, sorry but I don't understand your post. It's definitely not related to this issue. If you'd like to file a separate bug report, please open a new issue and include a minimal, self-contained code sample that demonstrates the problem you're seeing. Your code sample above is incomplete, so I'm not sure what it's trying to demonstrate. If you have questions about pylance language server features like semantic highlighting, the pylance-release project is a good place to post.
This is addressed in pyright 1.1.373.
Please consider the following code:
Shouldn't the last line above give an error since the two locks are swapped? Mypy does give an error, but pyright doesn't.
To get an error in pyright, one has to duplicate
f
:Unless this is expected behavior and mypy is wrong, the problem seems to be that in the code
there's just a single copy of
L1
andL2
involved. To get two independent instances, one has to basically create another function.The same happens in other contexts. Here's again some code I posted some time ago (that you didn't have time to read):
The point is that
adc1
, ...,adc4
are copies of the same function. I had to write the same function 4 times!I really hope this is a bug and not intended behavior!