-
-
Notifications
You must be signed in to change notification settings - Fork 32.7k
Closed
Labels
testsTests in the Lib/test dirTests in the Lib/test dirtopic-typingtype-featureA feature request or enhancementA feature request or enhancement
Description
Feature or enhancement
Right now we don't have a single test to dynamically create a PEP-695 class.
It is quite complex, because, for example, it cannot be done via type()
, you have to use types.new_class
. Example:
import typing
T = typing.TypeVar('T', infer_variance=True)
Klass = type(
'Klass',
(typing.Generic[T],),
{'__type_params__': (T,)},
)
Produces:
Traceback (most recent call last):
File "/Users/sobolev/Desktop/cpython2/ex.py", line 9, in <module>
Klass = type(
'Klass',
...<2 lines>...
# set_type_params,
)
TypeError: type() doesn't support MRO entry resolution; use types.new_class()
This is fine (I guess?)
Since types.new_class
is mentioned and it is there to create classes with complex MROs, we need to be sure that it works the same way as regular class My[T]: ...
I will send a PR.
Linked PRs
Metadata
Metadata
Assignees
Labels
testsTests in the Lib/test dirTests in the Lib/test dirtopic-typingtype-featureA feature request or enhancementA feature request or enhancement