You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I seem to be unable to satisfy a Protocol with an attribute that is hinted as another Protocol. The inner element does satisfy the inner protocol as shown by the call to g(). The mypy docs do describe recursive protocols as being supported which while a different thing than this seems to suggest that expecting protocols in general to be usable as hints in other protocols is reasonable.
main.py:29: error: Argument "x" to "f" has incompatible type "Outer"; expected "POuter"
main.py:29: note: Following member(s) of "Outer" have conflicts:
main.py:29: note: inner: expected "PInner", got "Inner"
Found 1 error in 1 file (checked 1 source file)
Your Environment
Mypy version used: 0.961
Mypy command-line flags: mypy-play.net default
Mypy configuration options from mypy.ini (and other config files): mypy-play.net default
Python version used: 3.10
Operating system and version: mypy-play.net default
The text was updated successfully, but these errors were encountered:
I think the error is correct. inner in POuter is a mutable attribute, which means that f is allowed to replace x.inner with an object of a different class that still implements the same protocol. Changing POuter to use a readonly property for inner fixes the error.
It took me a few attempts before I understood your explanation, but it makes sense now and does address both the example and my real case. The real case had three layers of protocols actually so I had to apply the read-only property pattern twice.
Bug Report
I seem to be unable to satisfy a
Protocol
with an attribute that is hinted as anotherProtocol
. The inner element does satisfy the inner protocol as shown by the call tog()
. The mypy docs do describe recursive protocols as being supported which while a different thing than this seems to suggest that expecting protocols in general to be usable as hints in other protocols is reasonable.To Reproduce
https://mypy-play.net/?mypy=latest&python=3.10&gist=62ec93fabc3a77038d6b35840a01863e
Expected Behavior
I expect the code to pass mypy.
Actual Behavior
Your Environment
mypy.ini
(and other config files): mypy-play.net defaultThe text was updated successfully, but these errors were encountered: