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

Remove (direct) use of constantly #12607

@DMRobertson

Description

@DMRobertson

The entire source tree uses constantly in exactly one file, originally added in #6377.

from constantly import NamedConstant, Names

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:

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:

  1. consistency across the source tree.
  2. mypy knows what an enum is; it don't know what a NamedConstant is. E.g. reveal_type(EventRedactBehaviour.AS_IS) yields synapse/handlers/message.py:1407: note: Revealed type is "Any".
  3. 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 stdlib enum
  • redefine the EventRedactBehaviour type in terms of enum
  • remove these lines from mypy.ini.
  • run the linter script: in particular, run mypy. Fix any errors that show up.

Metadata

Metadata

Assignees

No one assigned

    Labels

    T-TaskRefactoring, removal, replacement, enabling or disabling functionality, other engineering tasks.good first issueGood for newcomers

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions