Skip to main content
replaced http://codereview.stackexchange.com/ with https://codereview.stackexchange.com/
Source Link
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 questionthis answer to another question.

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.

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.

Source Link
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.