This repository was archived by the owner on Apr 26, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
This repository was archived by the owner on Apr 26, 2024. It is now read-only.
Remove (direct) use of constantly
#12607
Copy link
Copy link
Closed
Labels
T-TaskRefactoring, removal, replacement, enabling or disabling functionality, other engineering tasks.Refactoring, removal, replacement, enabling or disabling functionality, other engineering tasks.good first issueGood for newcomersGood for newcomers
Description
The entire source tree uses constantly
in exactly one file, originally added in #6377.
from constantly import NamedConstant, Names |
synapse/synapse/storage/databases/main/events_worker.py
Lines 153 to 160 in 8a87b44
class EventRedactBehaviour(Names): | |
""" | |
What to do when retrieving a redacted event from the database. | |
""" | |
AS_IS = NamedConstant() | |
REDACT = NamedConstant() | |
BLOCK = NamedConstant() |
In other places, we use the stdlib enum
module instead. For instance:
synapse/synapse/handlers/state_deltas.py
Lines 25 to 28 in e24ff8e
class MatchChange(Enum): | |
no_change = auto() | |
now_true = auto() | |
now_false = auto() |
I would like us to use the enum approach and ditch constantly, for three reasons:
- consistency across the source tree.
- mypy knows what an enum is; it don't know what a NamedConstant is. E.g.
reveal_type(EventRedactBehaviour.AS_IS)
yieldssynapse/handlers/message.py:1407: note: Revealed type is "Any"
. - I prefer using a well-known tool from the stdlib rather than the lesser-known constantly.
Task list:
- replace import of
constantly
with equivalent imports from stdlibenum
- redefine the
EventRedactBehaviour
type in terms ofenum
- remove these lines from mypy.ini.
- run the linter script: in particular, run mypy. Fix any errors that show up.
richvdhclokep
Metadata
Metadata
Assignees
Labels
T-TaskRefactoring, removal, replacement, enabling or disabling functionality, other engineering tasks.Refactoring, removal, replacement, enabling or disabling functionality, other engineering tasks.good first issueGood for newcomersGood for newcomers