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
for contrast has better runtime behavior (slightly, anyhow), but unfortunately, properties are not generic in the type system, so this ends up not type-checked, though ruff has no issue with this definition.
The text was updated successfully, but these errors were encountered:
@charliermarsh That would require duplicating type hints for the parameters. The return type might not be necessary (Pyright can infer that flawlessly), but the same cannot be said about parameter types.
Using properties here has multiple benefits, from better automatic type inference to better runtime behavior. With using methods, this would be multiple awaits for a simple wrapper or require self._c.__aexit__(exc_type, exc_value, traceback).__await__() which is harder for human reviewer to reason about. Perhaps that's not the strongest argument given the existing use of similar there to define __await__ in this particular case, but in general I try to avoid writing simple coroutines that only await other coroutines with pass-through.
Example code that works at runtime and which type checkers do understand
Code sample in pyright playground
Rewriting
ExecuteWrapper
as:for contrast has better runtime behavior (slightly, anyhow), but unfortunately, properties are not generic in the type system, so this ends up not type-checked, though ruff has no issue with this definition.
The text was updated successfully, but these errors were encountered: