pyrefly icon indicating copy to clipboard operation
pyrefly copied to clipboard

[Bug][CLI]: match does not narrow nested attribute types

Open yangdanny97 opened this issue 9 months ago • 2 comments

Describe the Bug

https://pyrefly.org/sandbox/?code=MQAg6gpgNgxg9gWwiALnVALZAFAngJwgDMpcQBlAQwDsATAIzgA8AaTASwGcQuRKQADpQDmEAFCgA7lkIhccAK4gYNEJPzsUENpwyVZNWiCgR91PowUpUuAe2rCe5vCgxxqAOgkSQACQgGBsqKAiYgRKYoCoTccEQc3JyGjEwAXD4AtCAA4hDWhJRQGSjsSDYCyDBYMADW9o4REAyUtZkgAKqcyIQAbqZQAPoothAAFACUqOj2nBUw1vYR+IRGwxWcbRBMFRpI1NaSmhiYyACSACIAouGR0RDcrpQHyJwKAgJw+NajEB7CHnwrHB4AhQnltCBhHBitDaMR7Jp2O42G4+vg2HkYOM2mANFo+HQQPgFM5cK53ME4SBaOxCPNSE45Ip8CB6Pg4JIuvgxER2QhyvUeKDPvkIH1CkMRmIYFBKJxuABBdIgFUgNJOawAHxAnBQ3Lh8S0utGlFSIAV42VqoQTyqfCtqtVKi65tGTAAvPYUBNLWJHf7Vb1+pKKiaPExsQGA36o0A

Codebase

No response

Other Attempts

No response

yangdanny97 avatar May 12 '25 18:05 yangdanny97

There are two issues:

first is that if x: A | B and we match x with some pattern A() it doesn't actually narrow x to A

second is that the nested attribute patterns B(int()), etc. do not narrow the properties for x. There are two kinds, positional and named attr patterns. The keyword one is easier, but the positional one could be tricky because it requires looking up __match_args__

yangdanny97 avatar May 15 '25 02:05 yangdanny97

the latter point also applies for keys in mapping patterns & indices in sequence patterns

yangdanny97 avatar May 15 '25 03:05 yangdanny97