Skip to content
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

TypedDictType crash with mypy 1.12.0 #2405

Closed
ncvc opened this issue Oct 14, 2024 · 2 comments · Fixed by #2408
Closed

TypedDictType crash with mypy 1.12.0 #2405

ncvc opened this issue Oct 14, 2024 · 2 comments · Fixed by #2408
Labels
bug Something isn't working

Comments

@ncvc
Copy link

ncvc commented Oct 14, 2024

Bug report

Mypy 1.12.0 crashes on calls to Django's .annotate(). It looks like the cause is the addition of the readonly_keys arg to TypedDictType in this PR.

What's wrong

Repro:

from django.db.models import QuerySet

from webserver.clients.models import Client


def annotate_client_queryset() -> QuerySet[Client]:
    return Client.objects.annotate(name="display_name")

Error:

$ mypy . --show-traceback
./webserver/client/public/query/client.py:10: error: INTERNAL ERROR -- Please try using mypy master on GitHub:
https://mypy.readthedocs.io/en/stable/common_issues.html#using-a-development-mypy-build
Please report a bug at https://github.com/python/mypy/issues
version: 1.12.0
Traceback (most recent call last):
  File "mypy/checkexpr.py", line 5847, in accept
  File "mypy/nodes.py", line 1969, in accept
  File "mypy/checkexpr.py", line 480, in visit_call_expr
  File "mypy/checkexpr.py", line 614, in visit_call_expr_inner
  File "mypy/checkexpr.py", line 1471, in check_call_expr_with_callee_type
  File "mypy/checkexpr.py", line 1565, in check_call
  File "mypy/checkexpr.py", line 1811, in check_callable_call
  File "mypy/checkexpr.py", line 1262, in apply_function_plugin
  File "/Users/ncvc/Library/Caches/pypoetry/virtualenvs/agent-webserver-p5YMsjuR-py3.12/lib/python3.12/site-packages/mypy_django_plugin/transformers/querysets.py", line 278, in extract_proper_type_queryset_annotate
    fields_dict = helpers.make_typeddict(api, fields=field_types, required_keys=set(field_types.keys()))
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/ncvc/Library/Caches/pypoetry/virtualenvs/agent-webserver-p5YMsjuR-py3.12/lib/python3.12/site-packages/mypy_django_plugin/lib/helpers.py", line 405, in make_typeddict
    typed_dict_type = TypedDictType(fields, required_keys=required_keys, fallback=fallback_type)
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: __init__() missing required argument 'readonly_keys' (pos 3)
./webserver/client/public/query/client.py:10: : note: use --pdb to drop into pdb

How is that should be

No crash

System information

  • OS: Mac
  • python version: 3.12
  • django version: 5.1.2
  • mypy version: 1.12.0
  • django-stubs version: 5.1.0
  • django-stubs-ext version: 5.1.0
@Andrioden
Copy link

Andrioden commented Oct 14, 2024

Crash Report

Getting same error, admittedly, the code that crashes was wrong. As the Player model do not got a zone field. When i removed the code, mypy works.

Ran mypy . --show-traceback

Traceback

(backend) PS C:\Repos\untitledgame\backend> mypy . --show-traceback                     
.\game\repos\zone\zone.py:188: error: INTERNAL ERROR -- Please try using mypy master on GitHub:
https://mypy.readthedocs.io/en/stable/common_issues.html#using-a-development-mypy-build
Please report a bug at https://github.com/python/mypy/issues
version: 1.12.0
Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "mypy\checkexpr.py", line 5847, in accept
  File "mypy\nodes.py", line 1969, in accept
  File "mypy\checkexpr.py", line 480, in visit_call_expr
  File "mypy\checkexpr.py", line 614, in visit_call_expr_inner
  File "mypy\checkexpr.py", line 1471, in check_call_expr_with_callee_type
  File "mypy\checkexpr.py", line 1565, in check_call
  File "mypy\checkexpr.py", line 1811, in check_callable_call
  File "mypy\checkexpr.py", line 1262, in apply_function_plugin
  File "C:\Users\andre\.virtualenvs\backend-jnn8gBG-\Lib\site-packages\mypy_django_plugin\transformers\querysets.py", line 352, in extract_proper_type_queryset_values
    row_type = helpers.make_typeddict(ctx.api, column_types, set(column_types.keys()))
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\andre\.virtualenvs\backend-jnn8gBG-\Lib\site-packages\mypy_django_plugin\lib\helpers.py", line 405, in make_typeddict
    typed_dict_type = TypedDictType(fields, required_keys=required_keys, fallback=fallback_type)
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: __init__() missing required argument 'readonly_keys' (pos 3)
.\game\repos\zone\zone.py:188: : note: use --pdb to drop into pdb

To Reproduce

Code that fails

return [p["id"] for p in Player.objects.filter(zone__x=x, zone__y=y).values("id")]

Relevant model

class Player(Model):
   # ... do not have any zone Field

Your Environment

  • Mypy version used: 1.12.0
  • Python version used: 3.12.1
  • Operating system and version: Windows 11 Home

@spapas
Copy link

spapas commented Oct 23, 2024

Hello friends any news on when this fix will be released on pypi ? TIA

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Development

Successfully merging a pull request may close this issue.

3 participants