Skip to main content
1 of 2
mkrieger1
  • 1.7k
  • 1
  • 14
  • 26
def is_prime(number: int) -> bool:
    …
    # number must be integer
    if type(number) != int:
        raise TypeError("Non-integers cannot be tested for primality.")

By providing a type annotation, you have already documented that only ints should be passed to the function, and you could even use static analysis tools to verify this. There is no need to do a dynamic type check on top of that.

Even without type annotations, there are good arguments for not doing type checks, as explained very well, for example, in section 4 of this answer to another question.

mkrieger1
  • 1.7k
  • 1
  • 14
  • 26