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

Upgrade to Mypy 1.4.0 #1572

Merged
merged 6 commits into from Jun 24, 2023
Merged

Conversation

christianbundy
Copy link
Contributor

Problem

We have tests that make assertions around Mypy output, and Mypy 1.4.0 contains changes to that output.

Solution

Use the new force_uppercase_builtins and force_union_syntax settings to keep our tests passing without mass edits to test files.

Related issues

dependabot bot and others added 3 commits June 21, 2023 02:59
Bumps [mypy](https://github.com/python/mypy) from 1.3.0 to 1.4.0.
- [Commits](python/mypy@v1.3.0...v1.4.0)

---
updated-dependencies:
- dependency-name: mypy
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
@christianbundy christianbundy marked this pull request as ready for review June 23, 2023 22:24
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.

Thank you!

mypy.ini Show resolved Hide resolved
@sobolevn sobolevn merged commit 510499b into typeddjango:master Jun 24, 2023
14 checks passed
@christianbundy
Copy link
Contributor Author

Thanks! Longer-term, how do we want to solve this? Originally I started fixing all of the errors, but I realized that the Mypy output is different depending on which Python version you're using since we don't specify python_version in mypy.ini.

I'm on the fence between:

  • python_version: 3.8 using the lowest supported Python version ensures that Mypy is using the more compatible semantics and will yell at us for doing things that won't work in Python 3.9
  • python_version: 3.11 using the highest supported Python version provides the latest and greatest in error messages / etc., and doesn't actually require that tests are run with Python 3.11

Do you have a preference? I'm happy to put together a PR that updates our output assertions, but I didn't want to put much time into it before aligning on a strategy.

@christianbundy
Copy link
Contributor Author

(I had a bit of free time this morning and opened #1577 as a proof of concept to consider.)

@@ -32,7 +32,7 @@ def find_stub_files(name: str) -> List[str]:
]

extras_require = {
"compatible-mypy": ["mypy>=1.3.0,<1.4"],
"compatible-mypy": ["mypy>=1.3.0,<1.5"],
Copy link
Collaborator

Choose a reason for hiding this comment

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

We have always updated the compatible-mypy lower bound as well.

descope bot added a commit to descope/django-descope that referenced this pull request Jul 18, 2023
This PR contains the following updates:

| Package | Type | Update | Change | Pending |
|---|---|---|---|---|
| [django-stubs](https://togithub.com/typeddjango/django-stubs)
([changelog](https://togithub.com/typeddjango/django-stubs/releases)) |
dev | patch | `4.2.1` -> `4.2.2` | `4.2.3` |

---

### Release Notes

<details>
<summary>typeddjango/django-stubs (django-stubs)</summary>

###
[`v4.2.2`](https://togithub.com/typeddjango/django-stubs/releases/tag/4.2.2)

[Compare
Source](https://togithub.com/typeddjango/django-stubs/compare/4.2.1...4.2.2)

#### Headline changes

-   **mypy 1.4:** Recommended mypy version updated to 1.4.x
- Support for `django-split-settings`, `django-configurations` and other
Django settings addons with `strict_settings = false` option, [see
README for
details](https://togithub.com/typeddjango/django-stubs#how-to-use-a-custom-library-to-handle-django-settings)
- We have now adopted [mypy's
stubtest](https://mypy.readthedocs.io/en/stable/stubtest.html) to
automatically find discrepancies between Django and django-stubs.

If you want to contribute to django-stubs but are not sure where to
start, have a look at [stubtest's TODO
list](https://togithub.com/typeddjango/django-stubs/blob/master/scripts/stubtest/allowlist_todo.txt)
file, which lists the many issues discovered by stubtest.

##### Django 4.2 changes

- Applied Django 4.2 deprecations by
[@&#8203;Alexerson](https://togithub.com/Alexerson) in
[typeddjango/django-stubs#1523
- Updated global settings and `AppConfig` class to match Django 4.2 by
[@&#8203;Alexerson](https://togithub.com/Alexerson) in
[typeddjango/django-stubs#1524
- Added types for new 'system checks' in Django 4.2 by
[@&#8203;Alexerson](https://togithub.com/Alexerson) in
[typeddjango/django-stubs#1526
- Added `ManifestStaticFilesStorage` new parameters by
[@&#8203;Alexerson](https://togithub.com/Alexerson) in
[typeddjango/django-stubs#1528
- Added new methods to `Sitemap` class by
[@&#8203;Alexerson](https://togithub.com/Alexerson) in
[typeddjango/django-stubs#1527
- Added new `headers=` parameter to `(Async)RequestFactory` and
`(Async)Client` classes by
[@&#8203;Alexerson](https://togithub.com/Alexerson) in
[typeddjango/django-stubs#1529
- Additional fixes by [@&#8203;intgr](https://togithub.com/intgr) in
[typeddjango/django-stubs#1537
- GDAL-related GeoDjango updates in Django 4.2 by
[@&#8203;Alexerson](https://togithub.com/Alexerson) in
[typeddjango/django-stubs#1525
- Added ORM `^` and `~` operator support, JSON lookup classes, Postgres
lookup classes, `ModelForm` changes, `json_script` template filter
parameters by [@&#8203;Alexerson](https://togithub.com/Alexerson) in
[typeddjango/django-stubs#1536
- Added and updated `db.backends` `DatabaseIntrospection` and
`DatabaseOperations` classes by
[@&#8203;GabDug](https://togithub.com/GabDug) in
[typeddjango/django-stubs#1571

##### Stubs additions

- Added `QuerySet._result_cache` attribute and `_fetch_all()` method by
[@&#8203;adamchainz](https://togithub.com/adamchainz) in
[typeddjango/django-stubs#1505
- Added `ModelAdmin.search_help_text` attribute by
[@&#8203;adamchainz](https://togithub.com/adamchainz) in
[typeddjango/django-stubs#1546
- Added email console handler `EmailBackend.write_message()` method by
[@&#8203;adamchainz](https://togithub.com/adamchainz) in
[typeddjango/django-stubs#1547
- Added `ModelAdmin.get_formset_kwargs()` method by
[@&#8203;adamchainz](https://togithub.com/adamchainz) in
[typeddjango/django-stubs#1545
- Added `Signal._live_receivers()` method by
[@&#8203;adamchainz](https://togithub.com/adamchainz) in
[typeddjango/django-stubs#1551
- Added `SQLCompiler._order_by_pairs()` method by
[@&#8203;adamchainz](https://togithub.com/adamchainz) in
[typeddjango/django-stubs#1586
- Added `memcache_key_warnings()` function by
[@&#8203;rvanlaar](https://togithub.com/rvanlaar) in
[typeddjango/django-stubs#1562

##### Stubs fixes

- Fixed `create_model_instance` incorrect data argument type by
[@&#8203;namper](https://togithub.com/namper) in
[typeddjango/django-stubs#1521
- Marked `RequestSite.{save,delete}` methods as `NoReturn` since they
always raise by [@&#8203;sobolevn](https://togithub.com/sobolevn) in
[typeddjango/django-stubs#1530
- Updated `SafeExceptionReporterFilter` attributes and removed obsolete
`CLEANSED_SUBSTITUTE` by
[@&#8203;mthuurne](https://togithub.com/mthuurne) in
[typeddjango/django-stubs#1540
- Changed `AppConfig.default_auto_field` to attribute instead of method
by [@&#8203;mthuurne](https://togithub.com/mthuurne) in
[typeddjango/django-stubs#1541
- Fixed `default_error_messages` attribute type of base `Field` and
`GenericIPAddressField` classes by
[@&#8203;asottile](https://togithub.com/asottile) in
[typeddjango/django-stubs#1538
- Improved spatialite `DatabaseWrapper` attributes by
[@&#8203;filbasi](https://togithub.com/filbasi) in
[typeddjango/django-stubs#1544
- Improved types for Signal `dispatch.dispatcher` by
[@&#8203;GabDug](https://togithub.com/GabDug) in
[typeddjango/django-stubs#1567
- Accept `str` field names for `Window.order_by()`, allow `None` for
`asc/desc` arguments by [@&#8203;GabDug](https://togithub.com/GabDug) in
[typeddjango/django-stubs#1574
- Updated many `django.utils.*` types from stubtest by
[@&#8203;GabDug](https://togithub.com/GabDug) in
[typeddjango/django-stubs#1575
- Updated many `db.migrations.operations` types from stubtest by
[@&#8203;GabDug](https://togithub.com/GabDug) in
[typeddjango/django-stubs#1583
- Added `StepValueValidator`, fixed argument for
`SRIDCacheEntry`/`EmailValidator`, improved `urls.resolvers` types by
[@&#8203;GabDug](https://togithub.com/GabDug) in
[typeddjango/django-stubs#1589

##### Plugin changes

- Fixed `ForeignKey` queryset filters on un-swapped models by
[@&#8203;UnknownPlatypus](https://togithub.com/UnknownPlatypus) in
[typeddjango/django-stubs#1495
- Add `strict_settings` option, allow runtime fallbacks for custom
settings by [@&#8203;sobolevn](https://togithub.com/sobolevn) in
[typeddjango/django-stubs#1557
- Add "Settings" section to README by
[@&#8203;sobolevn](https://togithub.com/sobolevn) in
[typeddjango/django-stubs#1581
- Automatically reset mypy cache when plugin settings change by
[@&#8203;sobolevn](https://togithub.com/sobolevn) in
[typeddjango/django-stubs#1578
- Fixed unhandled exception `KeyError: 'model_bases'` and related errors
by [@&#8203;intgr](https://togithub.com/intgr) in
[typeddjango/django-stubs#1563

##### django-stubs-ext

- Added `TypedDatabaseRouter` as database router base class by
[@&#8203;intgr](https://togithub.com/intgr) in
[typeddjango/django-stubs#1522

##### CI/testing

- CI: Replace isort with Ruff import sorting by
[@&#8203;intgr](https://togithub.com/intgr) in
[typeddjango/django-stubs#1507
- CI: Auto-remove unused imports using Ruff by
[@&#8203;intgr](https://togithub.com/intgr) in
[typeddjango/django-stubs#1508
- CI: Enable Ruff pyupgrade fixes by
[@&#8203;intgr](https://togithub.com/intgr) in
[typeddjango/django-stubs#1509
- CI: Run django-stubs-ext tests in full build matrix by
[@&#8203;intgr](https://togithub.com/intgr) in
[typeddjango/django-stubs#1552
- Remove typecheck test and clean things up by
[@&#8203;sobolevn](https://togithub.com/sobolevn) in
[typeddjango/django-stubs#1556
- Add stubtest with lots of errors (currently) by
[@&#8203;sobolevn](https://togithub.com/sobolevn) in
[typeddjango/django-stubs#1560
- Removed extra `--generate-allowlist` by
[@&#8203;sobolevn](https://togithub.com/sobolevn) in
[typeddjango/django-stubs#1576

##### Housekeeping

- Removed unsupported Django versions from package classifiers by
[@&#8203;intgr](https://togithub.com/intgr) in
[typeddjango/django-stubs#1553
- Removed try-except around import of `ArrayField` by
[@&#8203;sobolevn](https://togithub.com/sobolevn) in
[typeddjango/django-stubs#1558
- Reverted: Fix crash when psycopg2 is not installed by
[@&#8203;intgr](https://togithub.com/intgr) in
[typeddjango/django-stubs#1565
- Removed usage of `mypy_extensions` by
[@&#8203;sobolevn](https://togithub.com/sobolevn) in
[typeddjango/django-stubs#1566
- Upgrade to Mypy 1.4.0 by
[@&#8203;christianbundy](https://togithub.com/christianbundy) in
[typeddjango/django-stubs#1572
- Chore: set Black Python target to 3.8+ explicitely by
[@&#8203;GabDug](https://togithub.com/GabDug) in
[typeddjango/django-stubs#1573
- Update `flake8` plugins by
[@&#8203;sobolevn](https://togithub.com/sobolevn) in
[typeddjango/django-stubs#1579
- CI: Run tests and pre-commit using newest Python version by
[@&#8203;intgr](https://togithub.com/intgr) in
[typeddjango/django-stubs#1582
- Removed duplicate "import all" test file by
[@&#8203;adamchainz](https://togithub.com/adamchainz) in
[typeddjango/django-stubs#1587
- Update compatible-mypy to 1.4.x by
[@&#8203;intgr](https://togithub.com/intgr) in
[typeddjango/django-stubs#1588
- Version 4.2.2 release (django-stubs, django-stubs-ext) by
[@&#8203;intgr](https://togithub.com/intgr) in
[typeddjango/django-stubs#1590

#### New Contributors

- [@&#8203;namper](https://togithub.com/namper) made their first
contribution in
[typeddjango/django-stubs#1521
- [@&#8203;filbasi](https://togithub.com/filbasi) made their first
contribution in
[typeddjango/django-stubs#1544
- [@&#8203;GabDug](https://togithub.com/GabDug) made their first
contribution in
[typeddjango/django-stubs#1567
- [@&#8203;rvanlaar](https://togithub.com/rvanlaar) made their first
contribution in
[typeddjango/django-stubs#1562

**Full Changelog**:
typeddjango/django-stubs@4.2.1...4.2.2

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined),
Automerge - At any time (no schedule defined).

🚦 **Automerge**: Enabled.

♻ **Rebasing**: Whenever PR is behind base branch, or you tick the
rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update
again.

---

- [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check
this box

<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNi4xLjExIiwidXBkYXRlZEluVmVyIjoiMzYuMS4xMSIsInRhcmdldEJyYW5jaCI6Im1haW4ifQ==-->

Co-authored-by: descope[bot] <descope[bot]@users.noreply.github.com>
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.

None yet

3 participants