-
Notifications
You must be signed in to change notification settings - Fork 269
Open
Labels
topic: featureDiscussions about new features for Python's type annotationsDiscussions about new features for Python's type annotations
Description
(This is an extension to #241 and copied from the discussion there.)
What about having a magic class decorator (with no or minimal runtime effect) or a base class that declares a class as a "pure mixin"? A pure mixin could only be used for implementation inheritance, and it wouldn't be type checked by itself at all -- it would only be type checked as part of implementation inheritance. I think that this would allow type checkers to check some mixin use cases that are tricky right now with minimal code changes. The alternative would be to use ABCs to declare the things that the mixin expects to be defined elsewhere, but they are harder to use and arguably add boilerplate.
Example:
@puremixin
class MyMixin:
def do_stuff(self) -> int:
self.one_thing() # ok, even though not defined in this class
return self.second_thing(1) # also ok
class Thing(Implementation[MyMixin]):
def one_thing(self) -> None: pass # ok
def second_thing(self, x: int) -> str: # error: return type not compatible with do_stuff
return 'x'
mitar, phwh, alxmrs, clintval, koliyo and 9 more
Metadata
Metadata
Assignees
Labels
topic: featureDiscussions about new features for Python's type annotationsDiscussions about new features for Python's type annotations