Skip to main content
Code Review

Return to Answer

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 question 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.

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.8k
  • 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.

lang-py

AltStyle によって変換されたページ (->オリジナル) /