You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The Callable should be able to be tightened up on line 43.
So, that can probably become Callable[[_TSelf[_T]], _T].
However, looking at that, it's defined the _cache as _cache: Dict[str, _T]. Wouldn't that make it impossible to use this decorator multiple times on different values? e.g. If I have a class with a URL and a port as int, then the dict type would need to be dict[str, URL | int], which would then result in both attributes returning URL | int.
So, I think the _cache annotation might need some reworking... I suspect the Generic will need to be dropped from _TSelf and the dict may need to use Any. I'm not sure there's a clear way to do it accurately and type safe.
Following on from that, I tried adjusting the type of the Callable, but just seem to get errors (maybe because the class hasn't been fully defined at the time of the decorator, mypy doesn't recognise the class as matching the protocol?).
However, a quick test also revealed that the typing information is completely broken.
We need to add some assert_type()s to the tests and fix the type errors.
I was testing locally with the same instance of mypy on each repo. assert_type() on req.rel_url in an aiohttp test works correctly, but in the above test it fails with Any.
Reveals that all properties are Any. I'd also expect to get another error about the dict type, but currently don't.
I think the reason this is broken and why we don't see any real type errors is because of the pytest fixtures. I don't think there's a way to properly declare that we have the function itself. The current annotations of type[under_cache_property] want a subscripted type, without it mypy just infers type[under_cache_property[Any]] and therefore we don't get any proper type checking.
Might have to figure out something more awkward to use the imported function directly when type checking...
Activity
Dreamsorcerer commentedon Oct 8, 2024
Following on from that, I tried adjusting the type of the Callable, but just seem to get errors (maybe because the class hasn't been fully defined at the time of the decorator, mypy doesn't recognise the class as matching the protocol?).
However, a quick test also revealed that the typing information is completely broken.
We need to add some
assert_type()s to the tests and fix the type errors.Adjusting the first test to:
Reveals that all properties are
Any. I'd also expect to get another error about the dict type, but currently don't.Dreamsorcerer commentedon Oct 8, 2024
Hmm, the typing seems to work on aiohttp though, so I'm not sure what I'm doing differently here for it to not work...
webknjaz commentedon Oct 8, 2024
Different MyPy version?
Dreamsorcerer commentedon Oct 8, 2024
I was testing locally with the same instance of mypy on each repo. assert_type() on
req.rel_urlin an aiohttp test works correctly, but in the above test it fails with Any.webknjaz commentedon Oct 8, 2024
Any future import of annotations anywhere?
Dreamsorcerer commentedon Feb 26, 2025
I started on the yarl strict typing and this is definetely a problem, I get:
And it resulted in an extra 800 type errors.
I'll have to fix up propcache before I can go back to yarl.
Dreamsorcerer commentedon Feb 26, 2025
I think the reason this is broken and why we don't see any real type errors is because of the pytest fixtures. I don't think there's a way to properly declare that we have the function itself. The current annotations of
type[under_cache_property]want a subscripted type, without it mypy just inferstype[under_cache_property[Any]]and therefore we don't get any proper type checking.Might have to figure out something more awkward to use the imported function directly when type checking...