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

gh-104874: Document NewType.__supertype__ #104875

Merged
merged 4 commits into from
May 24, 2023
Merged

Conversation

JelleZijlstra
Copy link
Member

@JelleZijlstra JelleZijlstra commented May 24, 2023

@JelleZijlstra JelleZijlstra added needs backport to 3.11 only security fixes needs backport to 3.12 bug and security fixes labels May 24, 2023
@bedevere-bot bedevere-bot added the docs Documentation in the Doc dir label May 24, 2023
@JelleZijlstra JelleZijlstra marked this pull request as ready for review May 24, 2023 16:56
Copy link
Member

@AlexWaygood AlexWaygood left a comment

Choose a reason for hiding this comment

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

Looks good. We also test for __qualname__ and __module__; should we document those as well?

def test_special_attrs(self):
self.assertEqual(UserId.__name__, 'UserId')
self.assertEqual(UserId.__qualname__, 'UserId')
self.assertEqual(UserId.__module__, __name__)
self.assertEqual(UserId.__supertype__, int)
UserName = self.UserName
self.assertEqual(UserName.__name__, 'UserName')
self.assertEqual(UserName.__qualname__,
self.__class__.__qualname__ + '.UserName')
self.assertEqual(UserName.__module__, __name__)
self.assertEqual(UserName.__supertype__, str)

@JelleZijlstra
Copy link
Member Author

__qualname__ is actually wrong as implemented (it's always the same as __name__) and __module__ is mostly an implementation detail for pickling, so I'd prefer to leave those undocumented.

@AlexWaygood
Copy link
Member

__module__ is mostly an implementation detail for pickling

I feel like it could be useful to be able to know the module the newtype was defined in, and it seems useful to mention the ways in which instances of NewType are similar to classes, even though they're not classes.

Doc/library/typing.rst Outdated Show resolved Hide resolved
Doc/library/typing.rst Outdated Show resolved Hide resolved
@miss-islington
Copy link
Contributor

Thanks @JelleZijlstra for the PR, and @AlexWaygood for merging it 🌮🎉.. I'm working now to backport this PR to: 3.11, 3.12.
🐍🍒⛏🤖

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request May 24, 2023
(cherry picked from commit 41768a2)

Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
@bedevere-bot
Copy link

GH-104906 is a backport of this pull request to the 3.12 branch.

@bedevere-bot bedevere-bot removed the needs backport to 3.12 bug and security fixes label May 24, 2023
miss-islington pushed a commit to miss-islington/cpython that referenced this pull request May 24, 2023
(cherry picked from commit 41768a2)

Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
@bedevere-bot
Copy link

GH-104907 is a backport of this pull request to the 3.11 branch.

@bedevere-bot bedevere-bot removed the needs backport to 3.11 only security fixes label May 24, 2023
AlexWaygood pushed a commit that referenced this pull request May 24, 2023
gh-104874: Document NewType.__supertype__ (GH-104875)
(cherry picked from commit 41768a2)

Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
AlexWaygood pushed a commit that referenced this pull request May 24, 2023
gh-104874: Document NewType.__supertype__ (GH-104875)
(cherry picked from commit 41768a2)

Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs Documentation in the Doc dir
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Document NewType.__supertype__
4 participants