modal-labs / synchronicity

Synchronicity lets you interoperate with asynchronous Python APIs.
Apache License 2.0
80 stars 3 forks source link

Add Enum support to type-stubs #142

Closed ekzhang closed 6 months ago

ekzhang commented 6 months ago

This supports declaring Enum and subclasses of Enum like IntEnum inside translated files.

freider commented 6 months ago

I think this would fail if the inspected class definition uses from enum import Enum; class Blah(Enum) instead of class Blah(enum.Enum), since we don't "rewrite" the base class qualification but still just import enum.

I think it's acceptable to enforce "module qualified" Enums when needed though - there are some other cases the type stub generator has similar requirements at the moment iirc

mwaskom commented 6 months ago

I think it's acceptable to enforce "module qualified" Enums when needed though - there are some other cases the type stub generator has similar requirements at the moment iirc

Good catch here. Agree that it's acceptable (if not ideal) to have this constraint, although ideally we can give that feedback when generating the stubs rather than generating invalid stubs that cause errors at check-time.