-
Hi, I recently started using Pyright as my typechecker and in most cases I have no problems with that - that's really great tool. But today I met some behaviour I don't really understand. I think it would be the best to show an example first. import typing as t
class SomeProtocol(t.Protocol):
def some_meth(self) -> int: # pyright error: Function with declared return type "int" must return value on all code paths
"""
Some docstring documentation
""" This happens only when I don't provide an ellipsis ( import typing as t
class SomeProtocol(t.Protocol):
def some_meth(self) -> int: # No error here - everything seems fine
"""
Some docstring documentation
"""
... Why do I still need ellipsis in method body? As it is a protocol it should be obvious that there should not be any implementation there. When i don't provide docstring there - it's understandable I need |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
This is by design. You must include a This is an area that is under-specified in the typing spec, but I think that pyright's current design here is defensible, and I will be pushing for it to become the officially-documented behavior in protocols. In any case, I don't plan to change its behavior until we have this discussion in the typing forums and reach consensus about a specified behavior. |
Beta Was this translation helpful? Give feedback.
-
FYI this clashes with pylint rule W2301 |
Beta Was this translation helpful? Give feedback.
This is by design. You must include a
...
to indicate to pyright that the implementation is a placeholder and not an actual implementation that returns an implicitNone
.This is an area that is under-specified in the typing spec, but I think that pyright's current design here is defensible, and I will be pushing for it to become the officially-documented behavior in protocols. In any case, I don't plan to change its behavior until we have this discussion in the typing forums and reach consensus about a specified behavior.