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

mypy 0.990 breaks mypy_django_plugin #1235

Closed
intgr opened this issue Nov 7, 2022 · 2 comments · Fixed by #1239
Closed

mypy 0.990 breaks mypy_django_plugin #1235

intgr opened this issue Nov 7, 2022 · 2 comments · Fixed by #1239
Labels
bug Something isn't working

Comments

@intgr
Copy link
Collaborator

intgr commented Nov 7, 2022

mypy 0.990 was released today. When I have mypy 0.990 and mypy_django_plugin enabled, it fails with AssertionError on code that uses the django_cas_ng package.

The problematic code appears to be:

from django.conf import settings as django_settings
# ...
def get_service_url(request: HttpRequest, redirect_to: Optional[str] = None) -> str:
    """Generates application django service URL for CAS"""
    if hasattr(django_settings, 'CAS_ROOT_PROXIED_AS') and django_settings.CAS_ROOT_PROXIED_AS:
    # ^^^^^^^^^^^  

Link to source: https://github.com/django-cas-ng/django-cas-ng/blob/a67653cf85244aa137edbabb3c2e94e07f97c773/django_cas_ng/utils.py#L50-L53

Output:

.../site-packages/django_cas_ng/utils.py:53: 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: 0.990

The stacktrace:

Traceback (most recent call last):
  File "mypy/checkexpr.py", line 4665, in accept
  File "mypy/nodes.py", line 1957, in accept
  File "mypy/checkexpr.py", line 2769, in visit_op_expr
  File "mypy/checkexpr.py", line 3406, in check_boolean_op
  File "mypy/checker.py", line 5184, in find_isinstance_check
  File "mypy/checker.py", line 5223, in find_isinstance_check_helper
  File "mypy/checker.py", line 6486, in hasattr_type_maps
  File "mypy/checker.py", line 6522, in has_valid_attribute
  File "mypy/checkmember.py", line 191, in analyze_member_access
  File "mypy/checkmember.py", line 210, in _analyze_member_access
  File "mypy/checkmember.py", line 331, in analyze_instance_member_access
  File "mypy/checkmember.py", line 547, in analyze_member_var_access
  File ".../site-packages/mypy_django_plugin/transformers/settings.py", line 24, in get_type_of_settings_attribute
    assert isinstance(ctx.context, MemberExpr)
AssertionError: 

System information

  • OS: macOS
  • python version: 3.11.0
  • django version: 4.1.3
  • mypy version: 0.990
  • django-stubs version: 1.13.0
  • django-stubs-ext version: 0.7.0
@intgr intgr added the bug Something isn't working label Nov 7, 2022
@intgr
Copy link
Collaborator Author

intgr commented Nov 7, 2022

When I print out ctx.context in get_type_of_settings_attribute, I get TempNode:-1(Any)

ctx: AttributeContext(type=django.conf.LazySettings, default_attr_type=Any, context=TempNode:-1(Any), api=<mypy.checker.TypeChecker object at 0x10e936700>)

@intgr
Copy link
Collaborator Author

intgr commented Nov 8, 2022

Seems to be caused this new feature of mypy 0.990: python/mypy#13544

sobolevn pushed a commit that referenced this issue Nov 8, 2022
Fixes #1235. It seems this was caused by a new feature in mypy 0.990 involving `hasattr()`.
djbrown added a commit to djbrown/hbscorez that referenced this issue Dec 7, 2022
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.

1 participant