Use Python Class as a Type Hint

Use Python Class as a Type Hint

In the code above, Orange is a subclass of Fruit. How do we use type hint to specify that fruit_type in make_fruit should be a subclass of Fruit

Using a parent class as a type hint will give you a type error when using mypy. Use typing.Type instead.

Search

Related Posts

Related Posts

Scroll to Top

Work with Khuyen Tran

Work with Khuyen Tran