Skip to content

Fix a crash on mypy master branch #2670

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

Merged
merged 2 commits into from
May 9, 2025

Conversation

ngnpope
Copy link
Contributor

@ngnpope ngnpope commented May 9, 2025

I have made things!

In python/mypy#18818 the msg argument to analyze_member_access() was removed.
This will crash when mypy v1.16 gets released, so only pass msg if it is in the function signature.

Related issues

N/A

In python/mypy#18818 the `msg` argument to
`analyze_member_access()` was removed.
@ngnpope ngnpope marked this pull request as ready for review May 9, 2025 13:31
@ngnpope
Copy link
Contributor Author

ngnpope commented May 9, 2025

@sobolevn Perhaps we should also check mypy master in CI?


# TODO: [mypy 1.16+] Remove this workaround for passing `msg` to `analyze_member_access()`.
extra: dict[str, Any] = {}
if "msg" in inspect.signature(analyze_member_access).parameters: # mypy < 1.16
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bummer. Looks like inspect.signature() won't work because of mypyc...

ValueError: no signature found for builtin <built-in function analyze_member_access>


from mypy_django_plugin.lib import helpers

mypy_version_info = tuple(map(int, mypy_version.partition("+")[0].split(".")))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Switched to a version-based check. This is somewhat ugly, but I didn't want to add packaging as a dependency.

Copy link
Member

@sobolevn sobolevn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, we need more mypy versions to be tested in CI, including master one.

@sobolevn sobolevn merged commit 828ead6 into typeddjango:master May 9, 2025
37 checks passed
@ngnpope ngnpope deleted the fix-mypy-master-crash branch May 11, 2025 17:16
@stianjensen
Copy link
Contributor

mypy 1.16 released now, will django-stubs cut a corresponding release with this fix soon?

@sobolevn
Copy link
Member

yes!

asottile-sentry pushed a commit to getsentry/sentry-forked-django-stubs that referenced this pull request Jun 3, 2025
* Fix a crash on mypy master branch

In python/mypy#18818 the `msg` argument to
`analyze_member_access()` was removed.

* Switch to using a version-based check
asottile-sentry added a commit to getsentry/sentry-forked-django-stubs that referenced this pull request Jun 3, 2025
cherry-picked from typeddjango#2670

Co-authored-by: Nick Pope <nick@nickpope.me.uk>
jose-reveni pushed a commit to jose-reveni/django-stubs that referenced this pull request Jun 9, 2025
* Fix a crash on mypy master branch

In python/mypy#18818 the `msg` argument to
`analyze_member_access()` was removed.

* Switch to using a version-based check
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants