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
{{ message }}
Repository navigation
Regression: descriptors don't work on protocols #19262
Descriptors don't work when used as attributes on Protocols. The same code works on a regular class. This worked for many years up to and including mypy 1.15, but stopped working in 1.16.
Activity
brianschubert commentedon Jun 9, 2025
Thanks! Closing as duplicate of #19054
brianschubert commentedon Jun 9, 2025
As a workaround, you can try annotating the protocol member as a
ClassVar: https://mypy-play.net/?mypy=1.16.0&python=3.11&gist=9db8f68d93df061e745e4ce45c0daa5eeltoder commentedon Jun 9, 2025
Good idea, but unfortunately this makes actual classes incompatible with the protocol: https://mypy-play.net/?mypy=1.16.0&python=3.11&gist=9321d98d479917bd489d5be8872a509b
brianschubert commentedon Jun 9, 2025
Mypy will accept it if you also annotate the class assignments as
ClassVar, though I realize that could mean a lot of code churn: https://mypy-play.net/?mypy=1.16.0&python=3.11&gist=65196eafe5d72a12a5d7baadb2d5ace7eltoder commentedon Jun 9, 2025
Yeah, I don't want to update all my classes to work-around something that will hopefully get fixed.
eltoder commentedon Jun 9, 2025
It's also pretty verbose and ugly. Your snippet is missing the type argument to
ClassVar, so you lost typing on the actual class.