Search code examples
pythonpycharmpython-typing

Is it possible to have static type assertions in PyCharm?


I'd like Pycharm to assert when the user sets the value to something other than an int. I'm already using a type hint. Is there another way to get this functionality?

def someproperty(self, value):
    """
    :type value: int
    """
    assert isinstance(value, int)
    # other stuff

Solution

  • Using pycharm you can get somewhat close to static type checking, using type declarations and increasing the severity of the "Type checker" inspection:

    enter image description here

    This will make type checks very prominent in your code:

    enter image description here