How do you handle static type checking on genericized classes when substitution types are not known until runtime? /u/michelin_chalupa Python Education

I have a generic base class and have a mix of children which have fixed types, and others which are determined at runtime.

It’s easy enough to handle the fixed case, but how does one handle the dynamic one? Type checkers will complain if every annotation and inheritance does not substitute the Generics.

What are some patterns for these cases, assuming the TypeVars are bound to some base class? Do we just annotate/substitute with typing.Any everywhere, and call it a day?

submitted by /u/michelin_chalupa
[link] [comments]

​r/learnpython I have a generic base class and have a mix of children which have fixed types, and others which are determined at runtime. It’s easy enough to handle the fixed case, but how does one handle the dynamic one? Type checkers will complain if every annotation and inheritance does not substitute the Generics. What are some patterns for these cases, assuming the TypeVars are bound to some base class? Do we just annotate/substitute with typing.Any everywhere, and call it a day? submitted by /u/michelin_chalupa [link] [comments] 

I have a generic base class and have a mix of children which have fixed types, and others which are determined at runtime.

It’s easy enough to handle the fixed case, but how does one handle the dynamic one? Type checkers will complain if every annotation and inheritance does not substitute the Generics.

What are some patterns for these cases, assuming the TypeVars are bound to some base class? Do we just annotate/substitute with typing.Any everywhere, and call it a day?

submitted by /u/michelin_chalupa
[link] [comments] 

Leave a Reply

Your email address will not be published. Required fields are marked *