Could somebody please clarify the generally accepted way of defining a property as part of a Protocol?
I've been doing it like so:
from typing import Protocol
class MyProtocol(Protocol):
@property
def my_property(self):
""" Classes should have a my_property to conform to MyProtocol """
But Pycharm's built-in linter keeps complaining that a "Getter should return or yield something", hence my confusion.
Raising a NotImplementedError
makes the linter message go away, but doing that seems to fit more with an abstract class than with a Protocol.
@property
in a protocol? I mean, it's a protocol, not a base class – SydellenumberOfWheels
. If that weren’t allowed, you’d have to use a function likegetNumberOfWheels()
, which you wouldn’t otherwise do. Though if the language’s definition of properties is only stored properties (and doesn’t support computed properties), then the function is a more flexible bet. – Paleface