Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Type information incorrect when @cached methods are passed as parameters #16606

Open
clokep opened this issue Nov 6, 2023 · 1 comment
Open
Labels
O-Uncommon Most users are unlikely to come across this or unexpected workflow S-Minor Blocks non-critical functionality, workarounds exist. T-Defect Bugs, crashes, hangs, security vulnerabilities, or other reported issues.

Comments

@clokep
Copy link
Member

clokep commented Nov 6, 2023

If a method that is wrapped in @cached is passed into another function, e.g. run_in_background then the type information is incorrect; the current mypy plugin only updates the type information when it is called as a method, not when it is accessed as an attribute.

E.g. from #16590:

synapse/push/bulk_push_rule_evaluator.py:359: error: Missing positional argument "room_id" in call to "run_in_background"  [call-arg]
synapse/push/bulk_push_rule_evaluator.py:360: error: Argument 2 to "run_in_background" has incompatible type "str"; expected "RoomMemberWorkerStore"  [arg-type]

The method is not getting treated as bound (and there might be other issues too).

@clokep clokep added S-Minor Blocks non-critical functionality, workarounds exist. T-Defect Bugs, crashes, hangs, security vulnerabilities, or other reported issues. O-Uncommon Most users are unlikely to come across this or unexpected workflow labels Nov 6, 2023
@clokep
Copy link
Member Author

clokep commented Nov 6, 2023

I think we might need to expand the plugin to update the information when these sorts of methods are access as attributes instead of just when they're called as methods. mypy has other hooks we can use, but we need to be careful:

  1. That we don't apply the change twice (both as an attribute & as a method).
  2. That when access as an attribute it still appears as a CachedDescriptor (so that it has the invalidate method, etc.)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
O-Uncommon Most users are unlikely to come across this or unexpected workflow S-Minor Blocks non-critical functionality, workarounds exist. T-Defect Bugs, crashes, hangs, security vulnerabilities, or other reported issues.
Projects
None yet
Development

No branches or pull requests

1 participant