mypy icon indicating copy to clipboard operation
mypy copied to clipboard

feat(test): Failure test case for mypyc dictionary subclass views

Open BobTheBuidler opened this issue 8 months ago • 4 comments

I've created a failing test case for a mypyc bug with dict views as seen here: https://github.com/BobTheBuidler/checksum_dict/actions/runs/14843222374/job/41670896987

I added some new (working) test cases:

  • dict
    • keys
    • values
    • items
  • dict subclass
    • keys
    • values
    • items

and the failure cases:

  • dict subclass with 2 bases
    • keys
    • values
    • items

BobTheBuidler avatar May 12 '25 09:05 BobTheBuidler

@JukkaL Would you happen to know what I need to change so the tests are able to find the DefaultDict object in the typing module? Or is there someone better to ask about this?

BobTheBuidler avatar May 13 '25 16:05 BobTheBuidler

Fascinating, I've managed to make it work using a type: ignore comment, and now we have our successful (wut?) failure case!

BobTheBuidler avatar May 14 '25 03:05 BobTheBuidler

It's unclear what's the best approach here. @mypyc_attr(native_class=False) could act as a workaround (with some performance cost). We could also declare this as an unsupported use case, and generate an error with a note suggesting the @mypyc_attr workaround, in case it works.

JukkaL avatar Jun 07 '25 12:06 JukkaL

Hmm. That could work but I'd first like to try a bit to resolve it, I just need some help to know where I should look for the relevant code. Is there not a strightforward way to tell mypyc to only use the dict.keys c function when obj.keys actually resolves to dict.keys, and fallback to python's name resolution when it does not?

BobTheBuidler avatar Jun 07 '25 16:06 BobTheBuidler