Skip to content

Simplify the structure and docstrings of titles.py - #114

Merged
gevhaz merged 5 commits into
mainfrom
claude/stoic-cannon-7qdoh7
Oct 25, 2026
Merged

gevhaz merged 5 commits into
mainfrom
claude/stoic-cannon-7qdoh7

Conversation

@gevhaz

@gevhaz gevhaz commented Oct 24, 2026 •

Copy link
Copy Markdown
Owner

titles.py parses song and video titles with regular expressions, each of which finds one kind of extra part, like the "Live" in "Song (Live)", and captures it in a group named part. The functions in the module either remove such parts from a title or read them out of it. Removing already went through one helper, remove_parts(). Reading didn't: featured_artists(), versions() and is_instrumental() each matched the expressions and read the part group themselves. A new find_parts() now does the reading, so the public functions are all short calls to one of the two helpers.

The expressions were values in a dictionary, PATTERNS, and code picked them by key, e.g. find_parts(title, ["featuring"]). A misspelled key would only show up as a KeyError when that line ran. Each expression is now its own constant, like FEATURING_PATTERN, so a misspelling is an undefined name that ruff and mypy report. The lists of keys, like VERSION_PATTERN_NAMES, became lists of the constants, like VERSION_PATTERNS.

prune_title() applied every expression in the order of the dictionary, and that order differs from the order within the lists of versions, video notes and so on. Removing a part changes the text the next expression is matched against, so the order can matter. ALL_PATTERNS keeps the old order, so what prune_title() removes doesn't change.

The docstrings had grown longer than the code: the one-line functions had six to eight lines each, mostly restating the parameters, describing the implementation or giving background. CLAUDE.md used to ask for docstrings that can be understood without the code around them, which reads as "explain everything". Its new "Docstrings" section asks for what a caller needs instead: what the function gives, and the special cases its name and signature don't show. The docstrings in titles.py now follow it, which takes them from 94 lines to 51. I checked that each example in them is what the function returns.

The functions that take a title also now all call the parameter title, where prune_title() had original_title and remove_video_notes() had video_title.

🤖 Generated with Claude Code

https://claude.ai/code/session_01SwLevE2SHFqkDZuU4P28ij

@gevhaz
gevhaz force-pushed the claude/stoic-cannon-7qdoh7 branch from d384764 to ed4b44d Compare October 25, 2026 08:59
In titles.py, removing parts like "(Live)" from a title goes through
remove_parts(), but featured_artists(), versions() and is_instrumental()
each matched the regular expressions and read the "part" group
themselves. find_parts() does that once, so it and remove_parts() are
the only code that uses the expressions directly.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SwLevE2SHFqkDZuU4P28ij
In titles.py, most functions call the title they take "title", but
prune_title() called it "original_title" and remove_video_notes()
"video_title". The same name makes the signatures read alike.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SwLevE2SHFqkDZuU4P28ij
The regular expressions in titles.py were values in a dictionary,
PATTERNS, and code picked them by key, e.g. find_parts(title,
["featuring"]). A misspelled key is only noticed when that line runs,
as a KeyError. With each expression as a constant, like
FEATURING_PATTERN, a misspelling is an undefined name that ruff and
mypy report. ALL_PATTERNS lists them in the order prune_title() used
to take them from the dictionary.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SwLevE2SHFqkDZuU4P28ij
@gevhaz
gevhaz force-pushed the claude/stoic-cannon-7qdoh7 branch from ed4b44d to a41648e Compare October 25, 2026 09:44
@gevhaz gevhaz changed the title Make the functions in titles.py follow one structure Simplify the structure and docstrings of titles.py Oct 25, 2026
CLAUDE.md asked for docstrings that can be understood without the code
around them. That reads as "explain everything", so docstrings grew to
restate the signature and describe the implementation, which is more to
read and more to keep in sync. The new rules ask for what a caller
needs and leave the rest to the code and its comments.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SwLevE2SHFqkDZuU4P28ij
Most docstrings in titles.py restated the parameters, described
how the function works or gave background a caller doesn't need, so
the one-line functions had six to eight lines of docstring each. They
now say what the function gives and the special cases, as CLAUDE.md
asks. The reason split_artist_from_title() needs an artist on one side
of the dash moved to a comment in its body.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SwLevE2SHFqkDZuU4P28ij
@gevhaz
gevhaz force-pushed the claude/stoic-cannon-7qdoh7 branch from a41648e to 2ef2322 Compare October 25, 2026 09:45
@gevhaz
gevhaz merged commit 25be762 into main Oct 25, 2026
4 checks passed
@gevhaz
gevhaz deleted the claude/stoic-cannon-7qdoh7 branch October 25, 2026 09:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants