MCPcopy Index your code
hub / github.com/python/mypy / _verify_readonly_property

Function _verify_readonly_property

mypy/stubtest.py:1490–1516  ·  view source on GitHub ↗
(stub: nodes.Decorator, runtime: Any)

Source from the content-addressed store, hash-verified

1488
1489
1490def _verify_readonly_property(stub: nodes.Decorator, runtime: Any) -> Iterator[str]:
1491 assert stub.func.is_property
1492 if isinstance(runtime, property):
1493 yield from _verify_final_method(stub.func, runtime.fget, MISSING)
1494 return
1495 if isinstance(runtime, functools.cached_property):
1496 yield from _verify_final_method(stub.func, runtime.func, MISSING)
1497 return
1498 if _is_django_cached_property(runtime):
1499 yield from _verify_final_method(stub.func, runtime.func, MISSING)
1500 return
1501 if inspect.isdatadescriptor(runtime):
1502 # It's enough like a property...
1503 return
1504 # Sometimes attributes pretend to be properties, for instance, to express that they
1505 # are read only. So allowlist if runtime_type matches the return type of stub.
1506 runtime_type = get_mypy_type_of_runtime_value(runtime)
1507 func_type = (
1508 stub.func.type.ret_type if isinstance(stub.func.type, mypy.types.CallableType) else None
1509 )
1510 if (
1511 runtime_type is not None
1512 and func_type is not None
1513 and is_subtype_helper(runtime_type, func_type)
1514 ):
1515 return
1516 yield "is inconsistent, cannot reconcile @property on stub with runtime object"
1517
1518
1519def _verify_abstract_status(stub: nodes.FuncDef, runtime: Any) -> Iterator[str]:

Callers 1

verify_decoratorFunction · 0.85

Calls 5

isinstanceFunction · 0.85
_verify_final_methodFunction · 0.85
is_subtype_helperFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…