You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I propose that typing.NamedTupleMeta should allow creation of NamedTuples that inherit from things other than NamedTuple or Generic.
For example,
fromtypingimportNamedTupleclassBaseVector:
"""Shared functionality between all vectors."""
...
classVector2(NamedTuple, BaseVector):
"""Vector2 Object. Takes an x and a y coordinate."""x: floaty: floatclassVector3(NamedTuple, BaseVector):
"""Vector3 Object. Takes an x, y, and z coordinate."""x: floaty: floatz: float
Currently, if you try to do this, you get TypeError: can only inherit from a NamedTuple type and Generic being raised at runtime.
In particular, in typing, instead of this:
classNamedTupleMeta(type):
def__new__(cls, typename, bases, ns):
assert_NamedTupleinbasesforbaseinbases:
ifbaseisnot_NamedTupleandbaseisnotGeneric:
raiseTypeError(
'can only inherit from a NamedTuple type and Generic')
...
it would be changed to this:
classNamedTupleMeta(type):
def__new__(cls, typename, bases, ns):
if_NamedTuplenotinbases:
raiseTypeError(
'must inherit from a NamedTuple type')
...
Feature or enhancement
Proposal:
I propose that
typing.NamedTupleMeta
should allow creation of NamedTuples that inherit from things other than NamedTuple or Generic.For example,
Currently, if you try to do this, you get
TypeError: can only inherit from a NamedTuple type and Generic
being raised at runtime.In particular, in
typing
, instead of this:it would be changed to this:
Has this already been discussed elsewhere?
No response given
Links to previous discussion of this feature:
Kind of related but not really: #77258
The text was updated successfully, but these errors were encountered: