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

Remove __module__ assignment for TypeVar and friends #175

Merged
merged 1 commit into from May 22, 2023

Conversation

JelleZijlstra
Copy link
Member

No description provided.

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.

LGTM, considering no tests fail!

Seems like the __module__ = 'typing' thing was added in fafb5c5 (#77), but I can't find any rationale for why it was done in that PR thread. (Don't know if @cdce8p remembers?)

For context for other readers, the current situation results in some slightly bizarre behaviour when you call help() or repr() on typing_extensions.TypeVar (it claims to be from typing, even though it has some important differences to typing.TypeVar):

Python 3.12.0a7+ (heads/main:be0c106789, May 21 2023, 12:25:53) [MSC v.1932 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import typing_extensions, typing
>>> typing_extensions.TypeVar
<class 'typing.TypeVar'>
>>> typing_extensions.TypeVar("T", default=int)
~T
>>> typing.TypeVar
<class 'typing.TypeVar'>
>>> typing.TypeVar("T", default=int)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: 'default' is an invalid keyword argument for typevar()
>>> typing_extensions.TypeVar is typing.TypeVar
False
>>> help(typing_extensions.TypeVar)
Help on class TypeVar in module typing:

class TypeVar(builtins.object)
 |  TypeVar(name, *constraints, bound=None, covariant=False, contravariant=False, default=<sentinel>, infer_variance=False)
 |
 |  Type variable.
 |
 |  Class methods defined here:
 |
 |  __init_subclass__() -> None from typing_extensions._TypeVarMeta
 |      This method is called when a class is subclassed.
 |
 |      The default implementation does nothing. It may be
 |      overridden to extend subclasses.
 |
 |  ----------------------------------------------------------------------
 |  Data descriptors defined here:
 |
 |  __dict__
 |      dictionary for instance variables (if defined)
 |
 |  __weakref__
 |      list of weak references to the object (if defined)

@cdce8p
Copy link
Contributor

cdce8p commented May 22, 2023

Seems like the __module__ = 'typing' thing was added in fafb5c5 (#77), but I can't find any rationale for why it was done in that PR thread. (Don't know if @cdce8p remembers?)

Not sure anymore unfortunately. It's likely I missed that while copying the implementation from cpython.

@JelleZijlstra JelleZijlstra merged commit 773090f into python:main May 22, 2023
16 checks passed
@JelleZijlstra JelleZijlstra deleted the nomodule branch May 22, 2023 22:48
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.

None yet

3 participants