Есть скрипт:
Код: Выделить всё
from functools import cached_property
from collections.abc import Callable
from typing import TypeVar, Generic, Any, overload, Union
T = TypeVar("T")
class result_property(cached_property, Generic[T]):
def __init__(self, func: Callable[[Any], T]) -> None:
super().__init__(func)
def __set_name__(self, owner: type[Any], name: str) -> None:
super().__set_name__(owner, name)
@overload
def __get__(self, instance: None, owner: Union[type[Any], None] = None) -> 'result_property[T]': ...
@overload
def __get__(self, instance: object, owner: Union[type[Any], None] = None) -> T: ...
def __get__(self, instance, owner=None):
return super().__get__(instance, owner)
def func_str(s: str) -> None:
print(s)
class Foo:
@result_property
def prop_int(self) -> int:
return 1
foo = Foo()
func_str(foo.prop_int) # type error is expected here
Если я запускаю проверку mypy для этого сценария, он сообщает:
Код: Выделить всё
tmp.py:38: error: Argument 1 to "func_str" has incompatible type "int"; expected "str" [arg-type]
Found 1 error in 1 file (checked 1 source file)
Можно ли как-то изменить сценарий PyCharm, чтобы он также сообщал об ошибке типа в этой ситуации?
Подробнее здесь: https://stackoverflow.com/questions/776 ... d-property