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

TypeError: __init__() missing required argument 'readonly_keys' #18177

Closed
zachaysan opened this issue Nov 22, 2024 · 2 comments
Closed

TypeError: __init__() missing required argument 'readonly_keys' #18177

zachaysan opened this issue Nov 22, 2024 · 2 comments
Labels

Comments

@zachaysan
Copy link

Crash Report

Running mypy on the main Flagsmith code repo I'm hitting an error that I can't escape from even if I add the offending file to the exclude list or if I mark the offending line of code that causes the error as # type: ignore.

Traceback

Traceback (most recent call last):
  File "mypy/checkexpr.py", line 5848, 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 "/home/zach/.cache/pypoetry/virtualenvs/flagsmith-api-rl5v6uhh-py3.12/lib/python3.12/site-packages/mypy_django_plugin/transformers/querysets.py", line 311, in extract_proper_type_queryset_values
    row_type = helpers.make_typeddict(ctx.api, column_types, set(column_types.keys()))
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/zach/.cache/pypoetry/virtualenvs/flagsmith-api-rl5v6uhh-py3.12/lib/python3.12/site-packages/mypy_django_plugin/lib/helpers.py", line 355, in make_typeddict
    typed_dict_type = TypedDictType(fields, required_keys=required_keys, fallback=fallback_type)
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: __init__() missing required argument 'readonly_keys' (pos 3)

To Reproduce
Failure is on the type: ignore line below. The full code for the file is found here

def restrict_use_due_to_api_limit_grace_period_over() -> None:
    """
    Restrict API use once a grace period has ended.

    Since free plans don't have predefined subscription periods, we
    use a rolling thirty day period to filter them.
    """
    now = timezone.now()
    grace_period = now - timedelta(days=API_USAGE_GRACE_PERIOD)
    month_start = now - timedelta(30)
    queryset = (
	OrganisationAPIUsageNotification.objects.filter(  # type: ignore
            Q(
                notified_at__gte=month_start,
		notified_at__lte=grace_period,
                percent_usage__gte=100,
            )
            | Q(
                notified_at__gte=month_start,
                notified_at__lte=now,
                percent_usage__gte=100,
                organisation__breached_grace_period__isnull=False,
            )
        )
        .values("organisation")
        .annotate(max_value=Max("percent_usage"))
    )

Your Environment

  • Mypy version used: mypy 1.13.0 (compiled: yes)
  • Mypy command-line flags: poetry run mypy --config-file mypy.ini .
  • Mypy configuration options from mypy.ini (and other config files):
    Note that organisations/tasks.py is the file that is causing an issue, but even adding it to exclude doesn't help.
    [mypy]
    exclude = ^(tests/|organisations/tasks.py)$
    plugins =
        mypy_django_plugin.main
    
    [mypy.plugins.django-stubs]
    django_settings_module = "app.settings.local"
    
  • Python version used: Python 3.12.3
  • Operating system and version:
    Distributor ID:	Ubuntu
    Description:	Ubuntu 24.04.1 LTS
    Release:	24.04
    Codename:	noble
    
@brianschubert
Copy link
Collaborator

Hi! This is #17958 / typeddjango/django-stubs#2405. This should be fixed if you upgrade to django-stubs v5.1.1 or newer.

@brianschubert brianschubert closed this as not planned Won't fix, can't repro, duplicate, stale Nov 22, 2024
@zachaysan
Copy link
Author

Thank you so much for the help! It works as you suggested :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants