typing icon indicating copy to clipboard operation
typing copied to clipboard

Protocols: A utility to copy attributes from other types?

Open funkyfuture opened this issue 6 years ago • 1 comments

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.

funkyfuture avatar Jan 18 '19 18:01 funkyfuture

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.

ilevkivskyi avatar Jan 19 '19 03:01 ilevkivskyi

since i don't remember what use-case evoked this question …

funkyfuture avatar Apr 09 '23 10:04 funkyfuture