Skip to content

Add TypeAliasType #160

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

Merged
merged 10 commits into from
May 20, 2023
Merged
Show file tree
Hide file tree
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
5 changes: 5 additions & 0 deletions src/test_typing_extensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -4494,6 +4494,11 @@ def test_pickle(self):
unpickled = pickle.loads(pickled)
self.assertIs(unpickled, Alias)

def test_no_instance_subclassing(self):
with self.assertRaises(TypeError):
class MyAlias(TypeAliasType):
pass
Comment on lines +4627 to +4630
Copy link
Member

Choose a reason for hiding this comment

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

(Might be worth adding a test like this to python/cpython#103764 as well; I couldn't spot one)

Copy link
Member Author

Choose a reason for hiding this comment

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



if __name__ == '__main__':
main()
5 changes: 5 additions & 0 deletions src/typing_extensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -2678,6 +2678,11 @@ def __getitem__(self, parameters):
def __reduce__(self):
return self.__name__

def __init_subclass__(cls, *args, **kwargs):
raise TypeError(
"type 'typing_extensions.TypeAliasType' is not an acceptable base type"
)

# The presence of this method convinces typing._type_check
# that TypeAliasTypes are types.
def __call__(self):
Expand Down