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.
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
| return attrs | ||
|
|
||
|
|
||
| def _maybe_adjust_parameters(cls): |
There was a problem hiding this comment.
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
|
|
||
| @_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.
Strictly speaking, switching to using PEP-570 syntax here (and elsewhere) is a backwards-incompatible change. Not sure how we feel about that.
|
|
||
|
|
||
| if hasattr(typing, "Required"): | ||
| if hasattr(typing, "Required"): # 3.11+ |
There was a problem hiding this comment.
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.
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
| return NotImplemented | ||
| return True | ||
|
|
||
| if sys.version_info >= (3, 8): |
There was a problem hiding this comment.
It makes me so happy to drop the 3.7 branch here :)
|
|
||
| @_ensure_subclassable(lambda bases: (_TypedDict,)) | ||
| def TypedDict(__typename, __fields=_marker, *, total=True, **kwargs): | ||
| def TypedDict(typename, fields=_marker, /, *, total=True, **kwargs): |
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
No description provided.