Repository navigation
Simplify the structure and docstrings of titles.py - #114
Merged
Merged
Conversation
gevhaz
force-pushed
the
claude/stoic-cannon-7qdoh7
branch
from
October 25, 2026 08:59
d384764 to
ed4b44d
Compare
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
force-pushed
the
claude/stoic-cannon-7qdoh7
branch
from
October 25, 2026 09:44
ed4b44d to
a41648e
Compare
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
force-pushed
the
claude/stoic-cannon-7qdoh7
branch
from
October 25, 2026 09:45
a41648e to
2ef2322
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
titles.pyparses 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 namedpart. 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()andis_instrumental()each matched the expressions and read thepartgroup themselves. A newfind_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 aKeyErrorwhen that line ran. Each expression is now its own constant, likeFEATURING_PATTERN, so a misspelling is an undefined name that ruff and mypy report. The lists of keys, likeVERSION_PATTERN_NAMES, became lists of the constants, likeVERSION_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_PATTERNSkeeps the old order, so whatprune_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.mdused 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 intitles.pynow 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, whereprune_title()hadoriginal_titleandremove_video_notes()hadvideo_title.🤖 Generated with Claude Code
https://claude.ai/code/session_01SwLevE2SHFqkDZuU4P28ij