generics - Subclassing typing.GenericMeta in Python -


so want have (abstract) base class behaves sort of generic(i.e. subscripting typevars generates type-annotated base class can inherit make new generic classes), added features best defined in metaclass.

trying out, , looking @ source code of typing module, there doesn't seem easy way want without understanding , copying of logic , code of module.

is there better way?

if it's not clear, here's want:

class mymeta(genericmeta):     # own added behaviors/features     ...  class mygenericbase(metaclass=mymeta):     ...  t = typevar("t") class mygeneric(mygenericbase[t]):     ...  x : mygeneric[int] = mygeneric(1) 

as is, doing this:

t = typevar("t") class mybase(metaclass=genericmeta):     pass mybase[t] 

throws exception mybase not being generic class.


Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -