Is there a way of dynamically generating type hints for reflected code in mypy or pycharm?

Viewed 39

I am writing a utility which uses reflection quite heavily. For example, taking any random dataclass...

@dataclass
class Foo:
    title: str

I can run something like the following...

condition_filter = condition(Foo).title.like('bar')

The call to condition actually dynamically generates a new type at runtime with a signature based on the given input. The result is like the following...

class FooCondition:
    title: StrCondition

(Where StrCondition has the like method which is called to return some actual condition.)

Is there a way to also specify type hints for the generated FooCondition along with the class, so that my IDE / mypy can offer reasonable code completion / type checking?

0 Answers
Related