dropbox / pyannotate

Auto-generate PEP-484 annotations
Apache License 2.0
1.42k stars 59 forks source link

Support handling nested classes #85

Closed msullivan closed 5 years ago

msullivan commented 5 years ago

Without understanding the module hierarchy, we can't distinguish between a module and a class in a dotted name like foo.bar.A.B, and will insert code like from foo.bar.A import B, even though A is a class.

Work around this with a cruddy heuristic that names beginning with a capital letter are classes and not modules.

Another approach would be to introduce alternate punctuation like ! or : to separate the module and class part of a name. This would have the disadvantage of being pretty nonstandard but also not being an awful hack.

The "nonstandard" argument seemed compelling when I first went to implement this so I did the capital letter heuristic. But now it feels pretty weak to me and I'd lean towards switching to it, but I figured I'd get feedback first.

gvanrossum commented 5 years ago

I recommend : since this is used elsewhere too. -- --Guido (mobile)

msullivan commented 5 years ago

Do you have a preference about whether it should always emit : or only when a nested class is involved?

gvanrossum commented 5 years ago

I say always. We may have to bump the major version to indigo the incompatibility. -- --Guido (mobile)

gvanrossum commented 5 years ago

Thanks!