dflook / python-minifier

Transform Python source code into its most compact representation
MIT License
558 stars 41 forks source link

pyminify strips typing from NamedTuple replacing them with 0s? #12

Closed NoahCardoza closed 3 years ago

NoahCardoza commented 3 years ago

Example: class MyTuple(NamedTuple):url:0;domain:0;sitekey:0;kind:0;action:0

Should be: class MyTuple(NamedTuple):url:str;domain:str;sitekey:str;kind:CaptchaKindEnum;action:str

Is there any way to keep this from happening?

NoahCardoza commented 3 years ago

Never mind! I must have skipped over --no-remove-annotations.

Thanks!

NoahCardoza commented 3 years ago

On second thought, could some type of "--smart-no-remove-annotations" be possible? Where it removed typing from function declarations but detected things like NamedTuples that need typing?

NoahCardoza commented 3 years ago

After some messing around with the source I was able to achieve what I mentioned above. I also noticed you had already set it up to not strip typing on dataclasses, so I added the logic in that section.

Hopefully I submit a PR soon.