Skip to content

hm/phonemes.py: duplicated URL constants, mid-file imports, unused module-level helper #2

Description

@thorwhalen

Code-health observations in hm/phonemes.py, noted during the repo-polish pass
and deliberately left unchanged there (that pass was config/metadata only).

  1. Duplicated constants. rooturl / url_term_and_phones / url_phones /
    url_symbols are defined twice: once at module level and again verbatim as
    Phone class attributes. Two sources of truth for the same four URLs.

  2. Imports in the middle of the file. functools, operator, itertools
    and collections are imported after the first three function definitions,
    even though _text_to_term_and_phones (defined above them) uses
    methodcaller. It works only because the name is resolved at call time.
    Confusing to read and fragile if anything ever runs at import time.

  3. term_and_phones() looks vestigial. The module-level term_and_phones()
    function is not exported from hm/__init__.py and duplicates what
    Phone.tp does. Either promote it (export + docstring + doctest) or drop it.

  4. Phone.__init__ shadowing. self.url_term_and_phones = url_term_and_phones or self.url_term_and_phones reads the class attribute to default the instance
    attribute. It works, but a keyword-only argument with an explicit default
    would be clearer.

None of these are bugs today. Filing so the cleanup is pickup-able rather than
lost. Related: #1 (making the data fetch cacheable would touch the same code).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions