In a Python 3.7.1 project a method is defined with return type incompatible with the result type. However, the IDE, PyCharm 2018.2, gives no warnings. Here's a code example:
import numpy as np
from dataclasses import dataclass
import typing
# Definitions:
@dataclass(order=True)
class Theta:
vector: np.ndarray
def a(self) -> typing.AnyStr:
return self.vector.size
def b(self) -> str:
return self.vector.size
# Client code:
x = np.array([1, 2])
s = Theta(x).a().capitalize() # runtime errors
u = Theta(x).b().capitalize()
Is there a way to enforce type warnings, both in the definitions and the client code?
Note: There're several questions about Python type hints on SO, e.g., Pycharm strange warning when type hinting. However, they seem to focus on a different aspect.