Conversation
srittau
left a comment
There was a problem hiding this comment.
One typo, LG otherwise.
Co-authored-by: Sebastian Rittau <srittau@rittau.biz>
src/typing_extensions.py
Outdated
| self.__name__ = name | ||
| self.__value__ = value | ||
| self.__type_params__ = type_params |
There was a problem hiding this comment.
The PEP specifies that these attributes should be read-only, so shouldn't they be read-only properties here?
There was a problem hiding this comment.
I suppose we could do that, but it feels unnecessarily complicated.
There was a problem hiding this comment.
I don't feel strongly, but it doesn't feel that complicated to me, and I think it would be nice to match CPython on 3.12+ here 🤷♂️
|
It might also be worth adding an >>> class Foo(typing.TypeAliasType): ...
...
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: type 'typing.TypeAliasType' is not an acceptable base type |
| def test_no_instance_subclassing(self): | ||
| with self.assertRaises(TypeError): | ||
| class MyAlias(TypeAliasType): | ||
| pass |
There was a problem hiding this comment.
(Might be worth adding a test like this to python/cpython#103764 as well; I couldn't spot one)
| def_mod = _caller() | ||
| if def_mod != 'typing_extensions': | ||
| self.__module__ = def_mod |
There was a problem hiding this comment.
In python/cpython#103764, it looks like __module__ is always "typing", no matter what module the type alias is defined in:
>>> type T = int | str
>>> T.__module__
'typing'I like the behavior you have in this PR more, but it's more complicated to implement, and doesn't match the CPython PR currently :)
There was a problem hiding this comment.
(Resolved by python/cpython#104550, for future reference)
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
Fixes #159