Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
explicitly disallow typing.TypeVar subclassing
The existing test covering this case passed only incidentally. We
explicitly disallow doing this and add a proper error message.
  • Loading branch information
GBeauregard committed Feb 5, 2022
commit c51f48ee1a964c9e225b8d95db45336a91b439b6
3 changes: 3 additions & 0 deletions Lib/typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -818,6 +818,9 @@ def __init__(self, name, *constraints, bound=None,
if def_mod != 'typing':
self.__module__ = def_mod

def __mro_entries__(self, bases):
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.

It should be added not here, but in _TypeVarLike. ParamSpec instances are not subclassable too.

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.

And add it also in TypeVarTuple.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the feedback! I'll get to this soon and ping you when done (I'm currently in the process of moving across the country and starting a job)

raise TypeError("Cannot subclass an instance of TypeVar.")


class ParamSpecArgs(_Final, _Immutable, _root=True):
"""The args for a ParamSpec object.
Expand Down