Skip to content

Conversation

@AlexWaygood
Copy link
Member

No description provided.

@AlexWaygood AlexWaygood marked this pull request as ready for review July 6, 2023 17:38
Comment on lines -5432 to -5434
@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))
Copy link
Member Author

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

return attrs


def _maybe_adjust_parameters(cls):
Copy link
Member Author

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


@_ensure_subclassable(lambda bases: (_TypedDict,))
def TypedDict(__typename, __fields=_marker, *, total=True, **kwargs):
def TypedDict(typename, fields=_marker, /, *, total=True, **kwargs):
Copy link
Member Author

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.

Copy link
Member

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+
Copy link
Member Author

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

Comment on lines -2723 to -2732
# 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

Copy link
Member Author

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

return NotImplemented
return True

if sys.version_info >= (3, 8):
Copy link
Member Author

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 :)

Copy link
Member

@JelleZijlstra JelleZijlstra left a comment

Choose a reason for hiding this comment

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

Thanks!


@_ensure_subclassable(lambda bases: (_TypedDict,))
def TypedDict(__typename, __fields=_marker, *, total=True, **kwargs):
def TypedDict(typename, fields=_marker, /, *, total=True, **kwargs):
Copy link
Member

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.

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.

2 participants