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
dict ** unpacking does not respect descriptor #2751
Thinking twice about this, it seems like the current behavior is somewhat intentional given that CallabckModel.data is not initialized on the class, which in the strict runtime terms shouldn't trigger descriptor protocol.
That said, ORM libraries like SQLAlchemy likes to do this kind of stuff, and we seem to be the only type checker that currently chooses to strictly adhere to the runtime behaviors. I think we'd want some opinions from @stroxler the descriptor expert regarding what we should do here.
The behavior is indeed intentional. I think the tricky issue is that as you note, some magic libraries modify behavior, and we don't have an easy way to see this.
I think the best option would actually be to use an intersection type, if we trust our intersection behaviors enough - that's probably a controversial stance, but the issue is there's no right answer here, just different flavors of sometimes-right and sometimes-wrong.
The only way to avoid false positives is to unsoundly assume both possible behaviors. This is true of all ambiguous descriptors (this is one case, but callable types have related issues where they are impossible to analyze correctly, you have to make a dubious assumption that is sometimes wrong no matter what you do)
I feel pretty strongly about this (that intersections are the best answer to un-analyzable cases like this, and that a type checker that uses them will beat every other type checker in usability on relevant codebases), but I may also be the only person who thinks this.
If we had a tagged intersection with a reason, we could also make the abiguity visible to users, which is helpful since unsoundness means that they will hit runtime type errors if they try to rely on both behaviors. I think we want to avoid red squiggles, but some kind of trace in hover would be pretty helpful. This would also be useful for type-aware linters, which we've always thought is a plausible downstream toolset for Pyrefly
Activity
grievejia commentedon Mar 10, 2026
Thinking twice about this, it seems like the current behavior is somewhat intentional given that
CallabckModel.datais not initialized on the class, which in the strict runtime terms shouldn't trigger descriptor protocol.That said, ORM libraries like SQLAlchemy likes to do this kind of stuff, and we seem to be the only type checker that currently chooses to strictly adhere to the runtime behaviors. I think we'd want some opinions from @stroxler the descriptor expert regarding what we should do here.
stroxler commentedon Mar 12, 2026
The behavior is indeed intentional. I think the tricky issue is that as you note, some magic libraries modify behavior, and we don't have an easy way to see this.
I think the best option would actually be to use an intersection type, if we trust our intersection behaviors enough - that's probably a controversial stance, but the issue is there's no right answer here, just different flavors of sometimes-right and sometimes-wrong.
The only way to avoid false positives is to unsoundly assume both possible behaviors. This is true of all ambiguous descriptors (this is one case, but callable types have related issues where they are impossible to analyze correctly, you have to make a dubious assumption that is sometimes wrong no matter what you do)
I feel pretty strongly about this (that intersections are the best answer to un-analyzable cases like this, and that a type checker that uses them will beat every other type checker in usability on relevant codebases), but I may also be the only person who thinks this.
If we had a tagged intersection with a reason, we could also make the abiguity visible to users, which is helpful since unsoundness means that they will hit runtime type errors if they try to rely on both behaviors. I think we want to avoid red squiggles, but some kind of trace in hover would be pretty helpful. This would also be useful for type-aware linters, which we've always thought is a plausible downstream toolset for Pyrefly
rchen152 commentedon Jun 13, 2026
Pyrefly no longer errors on this example