typing
typing copied to clipboard
Protocols: A utility to copy attributes from other types?
is there a way to derive a Protocol based type from another class, so all attributes and their type annotations are declared, but may be overriden in the class body. a typical use-case would be to derive from Dict whose interface is imitated.
No, it is not possible to define a sane type system (to the best of my knowledge) where structural types are subtypes of nominal types. Such a tool/utility that will just generate a protocol (the source code) using a concrete class as a template may be useful however. You can write a module and publish it on PyPI.
since i don't remember what use-case evoked this question …