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
Expected class type but received "type" #2058
Comments
A static type checker needs to understand the class hierarchy for classes. It looks like you're dynamically creating new classes here. This is the equivalent of: def foo(x: Tuple[type, ...]):
class DynamicClass(x):
...
return DynamicClass Pyright also emits an error in this case. If you want to use static analysis, you should avoid this sort of dynamic class construction. You can suppress the error using a |
Oooh I see. The error message could be improved a bit. If I'm understanding you correctly it should say something more like:
Maybe. Anyway I'll close this. Thanks for the help (again)! |
This makes it impossible to type check Flask-SQLAlchemy's |
There's just lots of Python out there that can't really be statically type checked because it wasn't written in a way that's amenable to static type checking. Python type hinting is relatively new and there are a lot of issues with it so I imagine it will take a long time to get to the point where you can expect most code to be statically typed like you can with JavaScript/Typescript. You just have to resort to |
@davidism, I saw your related post in the mypy issue tracker. First of all, thank you for adding annotations to the Flask-SQLAlchemy library. It's great to hear that effort is underway! The code snippet that you posted in the mypy issue type checks in pyright without generating a type errors, although pyright does need to make a somewhat fragile assumption here. Namely, it assumes that a value that is annotated with the type If you'd like to discuss this further or explore solutions to other issues you're encountering as you add annotations, I recommend starting a new thread in the pyright discussions forum. |
The following code gives a type error:
It gives this error for
x
:Even though the type of
x
looks like it matches thetype
constructor:VS Code extension or command-line
Via Pylance 2021.6.3
Additional context
On Mac, with Python 3.8
The text was updated successfully, but these errors were encountered: