mypy, type hint: Union[float, int] -> is there a Number type?

Use float only, as int is implied in that type: def my_func(number: float): PEP 484 Type Hints specifically states that: Rather than requiring that users write import numbers and then use numbers.Float etc., this PEP proposes a straightforward shortcut that is almost as effective: when an argument is annotated as having type float, an argument … Read more

How can I catch a “catchable fatal error” on PHP type hinting?

Update: This is not a catchable fatal error anymore in php 7. Instead an “exception” is thrown. An “exception” (in scare quotes) that is not derived from Exception but Error; it’s still a Throwable and can be handled with a normal try-catch block. see https://wiki.php.net/rfc/throwable-interface E.g. <?php class ClassA { public function method_a (ClassB $b) … Read more

Using List/Tuple/etc. from typing vs directly referring type as list/tuple/etc

Until Python 3.9 added support for type hinting using standard collections, you had to use typing.Tuple and typing.List if you wanted to document what type the contents of the containers needed to be: def f(points: Tuple[float, float]): return map(do_stuff, points) Up until Python 3.8, tuple and list did not support being used as generic types. … Read more