-
Notifications
You must be signed in to change notification settings - Fork 765
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Pylance seem to have difference with class decorators #6272
Comments
Thanks for the issue. Do you have an example of where you're using this decorator? |
Yes, lets say I have a class defined like this:
And then in some other file I am doing something like this:
|
Your decorator is erasing all type information because it returns a value of type If you want to preserve the signature of the decorated class (or its constructor), there are several ways to express this. You could use a ParamSpec: def ignore_unknown_kwargs[**P, R](cls: Callable[P, R]) -> Callable[P, R]: ... Or you could use a regular type variable with a Callable upper bound: def ignore_unknown_kwargs[T: Callable](cls: T) -> T: ... Or you could use a regular type variable but specify that the pre-decorated type is a class: def ignore_unknown_kwargs[T](cls: type[T]) -> type[T]: ... There's (currently) no way in the Python type system to transform a signature in a way that adds an arbitrary number of untyped keyword arguments to a signature, so I don't see a way to reflect what your decorator is doing here. |
Well, that's interesting, because class it self defines those attributes that vscode cannot find. But I will not pretend to know inner workings of a type checker, so will close this for now and if somebody else have this same issue, they can find a solution in this thread. |
Hi!
This is a weird one. At first I thought there was an issue with extraPaths as those has been troubling, but turns out the issue was with my decorator.
When I use following decorator, pylance seem to be unable to find class properties:
When I rewrite the decorator to this:
Pylance seem to be able to find both correct and incorrect properties.
The text was updated successfully, but these errors were encountered: