Skip to content

Add support for mypy v1.16 #2703

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 11 commits into from
Jun 6, 2025
Merged

Add support for mypy v1.16 #2703

merged 11 commits into from
Jun 6, 2025

Conversation

ngnpope
Copy link
Contributor

@ngnpope ngnpope commented Jun 4, 2025

I have made things!

Finishes off necessary changes to upgrade to mypy v1.16

Related issues

Closes #2694, fixes #2696

@ngnpope
Copy link
Contributor Author

ngnpope commented Jun 4, 2025

@sobolevn Hopefully this covers the remaining changes required... 🤞🏻

Comment on lines 272 to 273
# Django incorrectly decorates this with `@classmethod`.
django.test.selenium.SeleniumTestCase.__init_subclass__
Copy link
Contributor Author

Choose a reason for hiding this comment

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

__init_subclass__ shouldn't be decorated with @classmethod even though it is one - it works implicitly. This is something that should be fixed in Django, but perhaps mypy is also unnecessarily picky here?

Copy link
Member

Choose a reason for hiding this comment

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

yes, this is a stubtest bug. Can you please fix it upstread? I will be happy to review and merge your changes.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, ok. So I did a little digging and this isn't an issue in stubtest. While the explicit @classmethod is not required, it is not causing the issue - a lazy assumption I made - it's actually that there is the following in typeshed:

https://github.com/python/typeshed/blob/567b488fc28978642bfeb70b29f11453b0ff124c/stdlib/unittest/case.pyi#L289-L291

The issue is that Django's SeleniumTestCase eventually subclasses TestCase but the latter accepts *args while the former doesn't. So this is another issue that should be fixed in Django. I'll update the comment to more accurately reflect that.

Comment on lines +14 to +17
main:4: note: Expected:
main:4: note: def __iter__(self) -> Iterator[Union[Tuple[Any, Any], Tuple[str, Iterable[Tuple[Any, Any]]]]]
main:4: note: Got:
main:4: note: def __iter__(self) -> Iterator[str]
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is annoying and perhaps a new bug in mypy v1.16? It doubles this note for some reason.

Copy link
Member

Choose a reason for hiding this comment

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

Yes, looks like so. Please, report upsteam.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Reported in python/mypy#19240

@ngnpope ngnpope marked this pull request as ready for review June 4, 2025 16:08
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.

THANKS A LOT! I am travelling right now, so I didn't have time to finish it. Amazing work.

One major question: it looks like there are some unrelated changed from the prev commit with uv

Comment on lines 272 to 273
# Django incorrectly decorates this with `@classmethod`.
django.test.selenium.SeleniumTestCase.__init_subclass__
Copy link
Member

Choose a reason for hiding this comment

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

yes, this is a stubtest bug. Can you please fix it upstread? I will be happy to review and merge your changes.

Comment on lines +14 to +17
main:4: note: Expected:
main:4: note: def __iter__(self) -> Iterator[Union[Tuple[Any, Any], Tuple[str, Iterable[Tuple[Any, Any]]]]]
main:4: note: Got:
main:4: note: def __iter__(self) -> Iterator[str]
Copy link
Member

Choose a reason for hiding this comment

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

Yes, looks like so. Please, report upsteam.

@ngnpope
Copy link
Contributor Author

ngnpope commented Jun 5, 2025

THANKS A LOT! I am travelling right now, so I didn't have time to finish it. Amazing work.

No problem! 😄

One major question: it looks like there are some unrelated changed from the prev commit with uv

Sorry for the confusion - it's because your original branch was behind master and I was targeting this at your original pull request, so needed to merge that in.

I'll change this pull request to be a replacement to yours instead of updating that one.

@ngnpope ngnpope changed the base branch from mypy1.16 to master June 5, 2025 14:47
@ngnpope ngnpope changed the title Mypy1.16 Add support for mypy v1.16 Jun 5, 2025
sobolevn and others added 10 commits June 5, 2025 15:49
Co-authored-by: Nick Pope <nick@nickpope.me.uk>
These were not grouped with the other cases of this issue under the
following heading in the allowlist:

```
Ignore @cached_property error "cannot reconcile @Property on stub with runtime object"
```

This fixes the following errors:

```
note: unused allowlist entry django.contrib.gis.db.backends.oracle.features.DatabaseFeatures.django_test_skips
note: unused allowlist entry django.contrib.gis.db.models.Lookup.output_field
note: unused allowlist entry django.db.backends.mysql.base.DatabaseWrapper.data_type_check_constraints
note: unused allowlist entry django.db.backends.mysql.base.DatabaseWrapper.display_name
note: unused allowlist entry django.db.backends.mysql.base.DatabaseWrapper.mysql_is_mariadb
note: unused allowlist entry django.db.backends.mysql.base.DatabaseWrapper.mysql_server_data
note: unused allowlist entry django.db.backends.mysql.base.DatabaseWrapper.mysql_server_info
note: unused allowlist entry django.db.backends.mysql.base.DatabaseWrapper.mysql_version
note: unused allowlist entry django.db.backends.mysql.base.DatabaseWrapper.sql_mode
note: unused allowlist entry django.db.models.Lookup.output_field
note: unused allowlist entry django.db.models.lookups.Lookup.output_field
note: unused allowlist entry django.db.models.sql.where.WhereNode.output_field
```
These are cached properties that override a plain attribute and so
stubtest complains with the following:

```
error: django.contrib.gis.db.backends.oracle.features.DatabaseFeatures.django_test_skips variable differs from runtime type functools.cached_property[Any]
Stub: in file /home/nick/Sources/_external/django-stubs/django-stubs/contrib/gis/db/backends/oracle/features.pyi:145
builtins.dict[builtins.str, builtins.set[builtins.str]]
Runtime:
<django.utils.functional.cached_property object at 0x7f628c1d8f50>

error: django.db.backends.oracle.features.DatabaseFeatures.django_test_skips variable differs from runtime type functools.cached_property[Any]
Stub: in file /home/nick/Sources/_external/django-stubs/django-stubs/db/backends/oracle/features.pyi:145
builtins.dict[builtins.str, builtins.set[builtins.str]]
Runtime:
<django.utils.functional.cached_property object at 0x7f628c1c5910>

error: django.db.backends.oracle.features.DatabaseFeatures.supports_frame_exclusion variable differs from runtime type functools.cached_property[Any]
Stub: in file /home/nick/Sources/_external/django-stubs/django-stubs/db/backends/oracle/features.pyi:102
builtins.bool
Runtime:
<django.utils.functional.cached_property object at 0x7f628c1c5b20>
```

There are many others of these that need looking at properly, so skip
them for now...
In the case of `Jinja2DivFormRenderer.__init__` - it will be gone come
Django 6.0 anyway when we can just remove this ignore.
Bisected to python/mypy#18847

Some of these look valid, others might be due to bugs, e.g. duplicate
note output that might need to be fixed in mypy?
Bisected to python/mypy#18876

It looks like this fixed a genuine problem! \o/
It seems that `Sequence[Sequence[str]] | Sequence[str]` simplifies to
`Sequence[Sequence[str]]` so we can remove this complexity. This more
simple annotation is also used for related values in
`django-stubs/db/backends/base/schema.pyi`.
@ngnpope
Copy link
Contributor Author

ngnpope commented Jun 5, 2025

@sobolevn have updated

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.

Thanks a lot! I will make a new release once I get back home.

@sobolevn sobolevn merged commit 748d53d into typeddjango:master Jun 6, 2025
37 checks passed
@ngnpope ngnpope deleted the mypy1.16 branch June 6, 2025 14:06
jose-reveni pushed a commit to jose-reveni/django-stubs that referenced this pull request Jun 9, 2025
Co-authored-by: sobolevn <mail@sobolevn.me>
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.

Mypy 1.16.0: TypeError: 'msg' is an invalid keyword argument for analyze_member_access()
2 participants