-
-
Notifications
You must be signed in to change notification settings - Fork 112
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
Drop support for Python 3.7 #267
Conversation
@skipUnless(TYPING_3_8_0, "NamedTuple had a bad signature on <=3.7") | ||
def test_signature_is_same_as_typing_NamedTuple(self): | ||
self.assertEqual(inspect.signature(NamedTuple), inspect.signature(typing.NamedTuple)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I deleted this test, as it no longer makes sense for us to have the same signature as typing.NamedTuple
on <3.13, following #240
@@ -535,46 +495,6 @@ def _get_protocol_attrs(cls): | |||
return attrs | |||
|
|||
|
|||
def _maybe_adjust_parameters(cls): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function used to be used for our implementation of TypedDict
and Protocol
, but it is now only used for our implementation of Protocol
on Python <3.8
@@ -1077,7 +870,7 @@ def __subclasscheck__(cls, other): | |||
_TypedDict = type.__new__(_TypedDictMeta, 'TypedDict', (), {}) | |||
|
|||
@_ensure_subclassable(lambda bases: (_TypedDict,)) | |||
def TypedDict(__typename, __fields=_marker, *, total=True, **kwargs): | |||
def TypedDict(typename, fields=_marker, /, *, total=True, **kwargs): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Strictly speaking, switching to using PEP-570 syntax here (and elsewhere) is a backwards-incompatible change. Not sure how we feel about that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm fine with it.
|
||
|
||
if hasattr(typing, "Required"): | ||
if hasattr(typing, "Required"): # 3.11+ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These kinds of comments are very useful when doing this kind of PR, so I added them in various places that didn't have them
# On 3.8+, alter the signature so that it matches typing.NamedTuple. | ||
# The signature of typing.NamedTuple on >=3.8 is invalid syntax in Python 3.7, | ||
# so just leave the signature as it is on 3.7. | ||
if sys.version_info >= (3, 8): | ||
_new_signature = '(typename, fields=None, /, **kwargs)' | ||
if isinstance(NamedTuple, _types.FunctionType): | ||
NamedTuple.__text_signature__ = _new_signature | ||
else: | ||
NamedTuple.__call__.__text_signature__ = _new_signature | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As mentioned above, monkey-patching the signature so that it appears to be the same as typing.NamedTuple
on all versions no longer makes sense following #240
@@ -737,146 +648,33 @@ def _proto_hook(cls, other): | |||
return NotImplemented | |||
return True | |||
|
|||
if sys.version_info >= (3, 8): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It makes me so happy to drop the 3.7 branch here :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
@@ -1077,7 +870,7 @@ def __subclasscheck__(cls, other): | |||
_TypedDict = type.__new__(_TypedDictMeta, 'TypedDict', (), {}) | |||
|
|||
@_ensure_subclassable(lambda bases: (_TypedDict,)) | |||
def TypedDict(__typename, __fields=_marker, *, total=True, **kwargs): | |||
def TypedDict(typename, fields=_marker, /, *, total=True, **kwargs): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm fine with it.
Co-authored-by: Jelle Zijlstra <[email protected]>
No description provided.