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

Completely drop Python 3.7 compatibility #1459

Merged
merged 4 commits into from
Apr 29, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,6 @@ This happens because these Django classes do not support [`__class_getitem__`](h
django_stubs_ext.monkeypatch()
```

Note: This monkey patching approach will only work when using Python 3.7 and higher, when the `__class_getitem__` magic method was introduced.

You can add extra types to patch with `django_stubs_ext.monkeypatch(extra_classes=[YourDesiredType])`

2. You can use strings instead: `'QuerySet[MyModel]'` and `'Manager[MyModel]'`, this way it will work as a type for `mypy` and as a regular `str` in runtime.
Expand Down
11 changes: 2 additions & 9 deletions django-stubs/core/mail/message.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@ from email.mime.base import MIMEBase
from email.mime.message import MIMEMessage
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText

# switch to tuple once https://github.com/python/mypy/issues/11098 is fixed
# remove Optional once python 3.7 is dropped (Tuple[str | None, ...] works with mypy on py3.10)
from typing import Any, Optional, Tuple, overload # noqa: Y022, Y037
from typing import Any, overload

from django.utils.functional import _StrOrPromise
from typing_extensions import TypeAlias
Expand Down Expand Up @@ -66,12 +63,8 @@ class SafeMIMEMultipart(MIMEMixin, MIMEMultipart): # type: ignore
def __setitem__(self, name: str, val: str) -> None: ...

_AttachmentContent: TypeAlias = bytes | EmailMessage | Message | SafeMIMEText | str
# switch to tuple once https://github.com/python/mypy/issues/11098 is fixed
# remove Optional once python 3.7 is dropped (Tuple[str | None, ...] works with mypy on py3.10)
_AttachmentTuple: TypeAlias = (
Tuple[str, _AttachmentContent]
| Tuple[Optional[str], _AttachmentContent, str]
| Tuple[str, _AttachmentContent, None]
tuple[str, _AttachmentContent] | tuple[str | None, _AttachmentContent, str] | tuple[str, _AttachmentContent, None]
Copy link
Collaborator Author

@intgr intgr Apr 27, 2023

Choose a reason for hiding this comment

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

Hrm? These comments were referencing Python 3.7, but I'm not sure whether this has anything to do with Python 3.7.

str | None or tuple[str] don't work on Python 3.8 runtime either.

But AFAIK it doesn't matter since .pyi files are only evaluated by mypy, not Python itself. Maybe I'm missing something.

Copy link
Member

Choose a reason for hiding this comment

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

These files are parsed by python, but not executed. I don't remember the origin of this comment, but I am happy that it is removed now :)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

These files are parsed by python, but not executed.

Genuinely interested, when does Python parse .pyi files?

Is this somehow related to the ast module (which used to be typed_ast but got merged into Python 3.8's ast)?

Copy link
Member

Choose a reason for hiding this comment

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

Yes, exactly. mypy uses ast.parse to get the Python's AST and then mypy builds its own AST around it.

)

class EmailMessage:
Expand Down
3 changes: 1 addition & 2 deletions django_stubs_ext/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,13 @@
maintainer="Marti Raudsepp",
maintainer_email="[email protected]",
py_modules=[],
python_requires=">=3.7",
python_requires=">=3.8",
install_requires=dependencies,
packages=["django_stubs_ext", *find_packages(exclude=["scripts"])],
package_data={"django_stubs_ext": ["py.typed"]},
classifiers=[
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
Expand Down
3 changes: 1 addition & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def find_stub_files(name: str) -> List[str]:
maintainer="Marti Raudsepp",
maintainer_email="[email protected]",
py_modules=[],
python_requires=">=3.7",
python_requires=">=3.8",
install_requires=dependencies,
extras_require=extras_require,
packages=["django-stubs", *find_packages(exclude=["scripts"])],
Expand All @@ -58,7 +58,6 @@ def find_stub_files(name: str) -> List[str]:
classifiers=[
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
Expand Down