-
-
Notifications
You must be signed in to change notification settings - Fork 485
WithAnnotations[X, Y] gives runtime error (but typechecker is happy) #719
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
Comments
For people who find this via google, the above can be "fixed" by replacing: PotentialRazorCustomer = WithAnnotations[User, MinedData] with: from typing import TYPE_CHECKING
if TYPE_CHECKING:
PotentialRazorCustomer = WithAnnotations[User, MinedData]
else:
PotentialRazorCustomer = WithAnnotations[User] This more-or-less gets you the best of both worlds. |
@jordanbray I would be happy to merge a PR with the fix! 👍 |
When I try to do this, I get the error #1024 . |
The above, sadly, does not work with VSCode and PyLance. |
From what I gathered it seems to be an error that occur with Python 3.8 ? I managed to fix it in my code base by replacing by replacing eg from typing_extensions import Annotated
class FormStatAnnotation(typing.TypedDict):
form_stats: typing.Mapping[str, typing.Mapping]
OrgUnitWithFormStat = Annotated[OrgUnit, FormStatAnnotation] |
Any updates on this? |
@olethanh But is that doing the same thing? This line is not easy to parse 😅:
|
Bug report
What's wrong
I am trying to use the
WithAnnotations
as documented with two parameters. The first is a django model, and the second is a typed dictionary. Here is a minified example:Works as anticipated. However, when I try to run the program (in this case, with
python manage.py shell < tester.py
) the traceback for both Option 1 and Option 2 above is the same (save line numbers):How is that should be
The above should typecheck correctly, and also run.
System information
python
version: 3.9.6django
version: 3.2mypy
version: 0.910django-stubs
version: 1.9.0django-stubs-ext
version: 0.3.1The text was updated successfully, but these errors were encountered: