FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

gh-104874: Document NewType.__supertype__ by JelleZijlstra · Pull Request #104875 · python/cpython · GitHub

/ cpython Public

gh-104874: Document NewType.__supertype__ - #104875

Merged
AlexWaygood merged 4 commits into
python:mainfrom
JelleZijlstra:supernew
May 24, 2023
Merged

gh-104874: Document NewType.__supertype__#104875
AlexWaygood merged 4 commits into
python:mainfrom
JelleZijlstra:supernew

Conversation

JelleZijlstra commented May 24, 2023
edited by github-actions Bot
Loading

Copy link
Copy Markdown
Member

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

AlexWaygood left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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)

Copy link
Copy Markdown
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.

Copy link
Copy Markdown
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.

Comment thread Doc/library/typing.rst Outdated
Comment thread Doc/library/typing.rst
JelleZijlstra requested a review from AlexWaygood May 24, 2023 20:21
AlexWaygood merged commit 41768a2 into python:main May 24, 2023

Copy link
Copy Markdown
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>

Copy link
Copy Markdown

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

bedevere-bot removed the needs backport to 3.12 only 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>

Copy link
Copy Markdown

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

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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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


Back | FazBrowse Home | New Git URL