Instagram / MonkeyType

A Python library that generates static type annotations by collecting runtime types
Other
4.74k stars 170 forks source link

Support type naming conflicts #209

Open PeterJCLaw opened 4 years ago

PeterJCLaw commented 4 years ago

If I have two separate classes with the same name, but defined in separate modules, where both end up being used within type signatures in a third file then MonkeyType will import both directly into the third file without any way to know which annotations relate to which of the classes.

Ideally MonkeyType would have a way to detect this and potentially change the import style it uses to compensate.

Feuermurmel commented 1 year ago

I also hit this issue in a way that made it a bit confusing to me. I was using monkeytype apply and got and error like this:

Could not resolve a unique qualified name for type Something at 48:5. Candidate names were: ['lala.Something', 'bli.bla.blubb.Something']

The source code position in the message refers to the stub that is internally generated by the command and not to the module specified on the command line. Maybe someone runs into this too and is less confused when they see this message. 🙃

Feuermurmel commented 1 year ago

I implemented a solution that seems to work in my case: https://github.com/Instagram/MonkeyType/pull/302

I don't think I'm willing to invest too much time into this beyond what was necessary to solve this issue for me. I'd also be happy if someone else copies the good parts of my PR an re-does the rest.

carljm commented 1 year ago

@Feuermurmel Thanks for the proof-of-concept, I'll take a look at it when I can find a moment and see if it looks mergeable.