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
invalid-inheritance error when a pydantic BaseModel extends a Protocol #5521
Thanks for the report! Python itself rejects this class with TypeError: metaclass conflict, since pydantic's ModelMetaclass and the _ProtocolMeta behind Protocol are unrelated subclasses of ABCMeta (sandbox), so I'm closing this as working as intended. Protocols are structural, though, so if you drop Foo from the bases, Bar is still accepted anywhere a Foo is expected.
I'm going to reopen this one for now and take it over, since I think there's probably a valid ask here, but I'm not sure what it is yet.
@DetachHead, Hassan is right that it looks like it errors when run by a Python interpreter. Is there a different example you have where this would be a false positive?
the reason i never ran into this before is because pyright doesn't handle extending Protocols properly at all, so i had to use my extremely hacky @implements decorator instead. but that doesn't work in pyrefly due to #5536 and #1180
i dont mind if you close this because it doesnt really seem fixable in pyrefly, unless we can have a separate pyrefly_extensions module with runtime fixes for some of these fundamentally broken typing features
another special casing situation to consider for protocols 🤣
the reason i never ran into this before is because pyright doesn't handle extending Protocols properly at all, so i had to use my DetachHead/basedpyright#775 (comment). but that doesn't work in pyrefly due to #5536 and #1180
wait, I never knew pyright didn't handle protocol at all, that's crazy! hopefully #5536 and #1180 will be fixed this week, and that it will support your @implements decorator. I'll put out a new release once it's landed
i dont mind if you close this because it doesnt really seem fixable in pyrefly, unless we can have a separate pyrefly_extensions module with runtime fixes for some of these fundamentally broken typing features
I may open a new issue or discussion post with possible ideas for things to include in a pyrefly_extensions module and add this in
Activity
shahhamdihassan commentedon Nov 5, 2026
Thanks for the report! Python itself rejects this class with
TypeError: metaclass conflict, since pydantic'sModelMetaclassand the_ProtocolMetabehindProtocolare unrelated subclasses ofABCMeta(sandbox), so I'm closing this as working as intended. Protocols are structural, though, so if you dropFoofrom the bases,Baris still accepted anywhere aFoois expected.connernilsen commentedon Nov 6, 2026
I'm going to reopen this one for now and take it over, since I think there's probably a valid ask here, but I'm not sure what it is yet.
@DetachHead, Hassan is right that it looks like it errors when run by a Python interpreter. Is there a different example you have where this would be a false positive?
DetachHead commentedon Nov 9, 2026
wow, i had no idea this doesnt work at runtime... just another thing to add to the long list of everything wrong with
Protocols in pythonthe reason i never ran into this before is because pyright doesn't handle extending
Protocols properly at all, so i had to use my extremely hacky@implementsdecorator instead. but that doesn't work in pyrefly due to #5536 and #1180i dont mind if you close this because it doesnt really seem fixable in pyrefly, unless we can have a separate
pyrefly_extensionsmodule with runtime fixes for some of these fundamentally broken typing featuresconnernilsen commentedon Nov 9, 2026
another special casing situation to consider for protocols 🤣
wait, I never knew pyright didn't handle protocol at all, that's crazy! hopefully #5536 and #1180 will be fixed this week, and that it will support your
@implementsdecorator. I'll put out a new release once it's landedI may open a new issue or discussion post with possible ideas for things to include in a
pyrefly_extensionsmodule and add this inEdit: #5600 created