Skip to content

Upgrade django-stubs again, unpin mypy, and add more annotations - #36072

Merged
kdmccormick merged 3 commits into
openedx:masterfrom
kdmccormick:kdmccormick/unpin-mypy
Jan 9, 2025
Merged

Upgrade django-stubs again, unpin mypy, and add more annotations#36072
kdmccormick merged 3 commits into
openedx:masterfrom
kdmccormick:kdmccormick/unpin-mypy

Conversation

@kdmccormick

@kdmccormick kdmccormick commented Jan 2, 2025

Copy link
Copy Markdown
Member

This gets us to the latest version of both django-stubs and mypy, while constraining django-stubs<6, which should ensure that the stubs stay compatible as long as we are on django 4.x.x or django 5.x.x. We had previously upgraded django-stubs from 1.16.0 to 4.2.7, but it seems that, due to a regression in django-stubs 4.2.7, we should just go all they way forward to django-stubs 5.x.x.

This will let us take advantage of mypy's latest features and bugfixes, allowing us to write richer type annotations. It will also help ensure that any type-checked modules are more likely to be compatible with django 5+. It should have no functional impact.

As part of this, we've needed to introduce some new utilities in the openedx.core.types package.

See commits for more details.

Closes: #35667

@kdmccormick kdmccormick mentioned this pull request Jan 2, 2025
@kdmccormick
kdmccormick force-pushed the kdmccormick/unpin-mypy branch from 669c6a9 to 3d99ebb Compare January 7, 2025 15:20
@kdmccormick kdmccormick changed the title build: Unpin mypy and upgrade it to latest Upgrade django-stubs again, and unpin mypy Jan 7, 2025
@kdmccormick kdmccormick changed the title Upgrade django-stubs again, and unpin mypy Upgrade django-stubs Again, and Unpin mypy Jan 7, 2025
Comment thread requirements/constraints.txt Outdated
@kdmccormick kdmccormick changed the title Upgrade django-stubs Again, and Unpin mypy Upgrade django-stubs again, unpin mypy, and add more annotations Jan 7, 2025
@kdmccormick
kdmccormick force-pushed the kdmccormick/unpin-mypy branch from 241c7c9 to b4407a1 Compare January 7, 2025 16:57
@kdmccormick

Copy link
Copy Markdown
Member Author

@bradenmacdonald or @regisb , I could use one of your pairs of eyes on this, particularly for the new fancy stuff under openedx.core.types.

@kdmccormick
kdmccormick marked this pull request as ready for review January 7, 2025 16:58
This is possible now that django-stubs and djangorestframework-stubs
are unpinned:
openedx@a5b773c

which became possible once we upgraded to django 4.2.

Closes: openedx#35667
@kdmccormick
kdmccormick force-pushed the kdmccormick/unpin-mypy branch from b4407a1 to ea34e26 Compare January 9, 2025 14:01

@regisb regisb left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This looks great to me. I don't see any issue in openedx.core.types.

I recently discovered that you had added mypy testing to edx-platform CI, which is great! Coverage is still lacking of course, but I'm hoping we can improve that in the future. Maybe with a hackathon?

I also love how your PR is fixing actual bugs that you discovered thanks to mypy.

Comment thread openedx/core/types/meta.py
Comment thread openedx/core/types/meta.py Outdated
Comment thread openedx/core/types/meta.py Outdated
Rather than constraining django-stubs' major version to our django
major version (4.x.x), we are going to go one ahead (5.x.x), as
recommended by python/mypy#17958

Also includes an unrelated common_constraints update.
Includes some new Request type annotations in openedx.core.types.http,
plus a new meta-utility @type_annotation_only to ensure that we don't
accidentally start instantiating those new classes.
@kdmccormick
kdmccormick force-pushed the kdmccormick/unpin-mypy branch from ea34e26 to 69bcbac Compare January 9, 2025 15:07
@kdmccormick
kdmccormick enabled auto-merge (rebase) January 9, 2025 15:07
@kdmccormick
kdmccormick removed the request for review from bradenmacdonald January 9, 2025 15:10
@kdmccormick

Copy link
Copy Markdown
Member Author

I recently discovered that you had added mypy testing to edx-platform CI, which is great! Coverage is still lacking of course, but I'm hoping we can improve that in the future. Maybe with a hackathon?

You can thank Braden for getting the ball rolling with mypy in this repo! I too would love to increase coverage--if you kicked off a hackathon, I would certainly throw my weight behind it.

@kdmccormick
kdmccormick merged commit 3dc28ab into openedx:master Jan 9, 2025
@kdmccormick
kdmccormick deleted the kdmccormick/unpin-mypy branch January 9, 2025 15:31
@edx-pipeline-bot

Copy link
Copy Markdown
Contributor

2U Release Notice: This PR has been deployed to the edX staging environment in preparation for a release to production.

@bradenmacdonald

Copy link
Copy Markdown
Contributor

I recently discovered that you had added mypy testing to edx-platform CI, which is great!

You can thank Braden for getting the ball rolling with mypy in this repo!

The very first work on mypy in platform was done by @regisb, via #27575 + #27786 as far as I know! I was just the first to build on it and expand to multiple apps in this repo (#32591).

Nice work on this PR @kdmccormick :)

@edx-pipeline-bot

Copy link
Copy Markdown
Contributor

2U Release Notice: This PR has been deployed to the edX production environment.

1 similar comment
@edx-pipeline-bot

Copy link
Copy Markdown
Contributor

2U Release Notice: This PR has been deployed to the edX production environment.

@kdmccormick

kdmccormick commented Jan 9, 2025

Copy link
Copy Markdown
Member Author

Oh right--Regis added mypy, OC has been using it a lot, and I think Axim/Arbisoft added it to CI.

image

Regardless, good work all around--types are great and I want to use them everywhere :)

@edx-pipeline-bot

Copy link
Copy Markdown
Contributor

2U Release Notice: This PR has been deployed to the edX production environment.

1 similar comment
@edx-pipeline-bot

Copy link
Copy Markdown
Contributor

2U Release Notice: This PR has been deployed to the edX production environment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unpin mypy

5 participants