Skip to content

chore: simplify website/ Python and polish sponsors section#3076

Merged
vinta merged 23 commits intomasterfrom
chore/code-cleanup
Apr 19, 2026
Merged

chore: simplify website/ Python and polish sponsors section#3076
vinta merged 23 commits intomasterfrom
chore/code-cleanup

Conversation

@vinta
Copy link
Copy Markdown
Owner

@vinta vinta commented Apr 19, 2026

Summary

  • Python simplifications in website/ (17 commits): deleted dead code, tightened types, modernized syntax. Tests: 117 → 113 (4 format_stars_short tests removed along with the inlined function). uvx ty check website/: 15 diagnostics → 0.
  • Sponsors section CSS polish (6 commits): bumped section heading size, removed decorative arrow from "Become a sponsor", switched border underline to text-decoration for tighter alignment.

Python cleanup highlights

  • Deleted dead helpers (_find_first_link, _is_leading_link, format_stars_short) and stale StarData TypedDict
  • Tightened extract_entries parameter types, build() now takes Path, load_stars returns dict[str, dict]
  • Added _href helper to narrow attrGet("href") return type
  • Swapped manual batching loop for itertools.batched (3.13 stdlib)
  • Cache-age check now uses timedelta instead of total_seconds()/3600
  • Collapsed render_inline_html/render_inline_text into a shared _render_inline helper
  • Fused _parse_sponsor_item double-walk into a single pass
  • datetime.now(timezone.utc)datetime.now(UTC)
  • Modernized test_readme_parser to use pathlib

Sponsors styling

  • .sponsor-meta .section-label: --text-sm--text-lg
  • Removed <span class="sponsor-become-arrow"> + orphaned CSS rules
  • .sponsor-become: border-bottom + padding-bottomtext-decoration: underline with text-underline-offset: 0.2em
  • Hover state on the underline uses --accent-underline (lighter tan)

Test plan

  • uv run pytest — 113 passing
  • uvx ty check website/ — all checks passed
  • Visually verify sponsors section in browser (make preview)

🤖 Generated with Claude Code

vinta and others added 23 commits April 19, 2026 21:53
…build_graphql_query

The empty-parts check after the loop makes the upfront `if not repos: return ""` guard redundant.

Co-Authored-By: Claude <noreply@anthropic.com>
State reset (current_group_name = None, current_group_cats = []) was
duplicated in both branches of the early-return guard. Move it after
the conditional so it runs exactly once regardless of path.

Co-Authored-By: Claude <noreply@anthropic.com>
Python 3.11 introduced datetime.UTC as a cleaner alias for
datetime.timezone.utc. Both build.py and fetch_github_stars.py
are updated to use the shorter form.

Co-Authored-By: Claude <noreply@anthropic.com>
… fetch_batch

client is the only non-first param and is always required, so the * separator
adds no clarity. Update the call site accordingly.

Co-Authored-By: Claude <noreply@anthropic.com>
Remove internal str->Path conversion; callers and tests now pass
Path objects directly.

Co-Authored-By: Claude <noreply@anthropic.com>
…tion/ParsedGroup

Replace loose list[dict] annotations with concrete TypedDicts imported
from readme_parser so ty can verify call-site compatibility.

Co-Authored-By: Claude <noreply@anthropic.com>
…to dict[str, dict]

Cache-write shape mismatches the TypedDict and callers mix .get() and
direct access, so the stricter type was providing false safety. Using
dict[str, dict] accurately reflects the actual runtime contract.

Co-Authored-By: Claude <noreply@anthropic.com>
Extracts a _href(link) helper that returns link.attrGet('href') narrowed
to str (falling back to '') instead of the raw str|int|float|None union.
Replaces all four attrGet('href') or '' call sites with _href(), fixing
ty errors where the widened union leaked into TypedDict url fields.

Co-Authored-By: Claude <noreply@anthropic.com>
…line, "link")

The private helper duplicated _find_child with a hardcoded type filter.
Remove it and call the general helper directly at both call sites.

Co-Authored-By: Claude <noreply@anthropic.com>
The helper was only called once and the bool(inline.children) guard
was redundant: first_link being non-None already implies inline.children
is non-empty.

Co-Authored-By: Claude <noreply@anthropic.com>
The helper only appeared once and the logic is two lines, so the named
function added indirection without clarity. Removed the four dedicated
unit tests that covered the function directly.

Co-Authored-By: Claude <noreply@anthropic.com>
…s.batched

Use itertools.batched (stdlib since Python 3.12, targeted by this project)
instead of manual range(0, N, BATCH_SIZE) slicing. Loosen fetch_batch,
build_graphql_query, and parse_graphql_response signatures from list[str]
to Sequence[str] since batched yields tuples.

Co-Authored-By: Claude <noreply@anthropic.com>
Use timedelta(hours=CACHE_MAX_AGE_HOURS) so the cache-age check
reads at the intended hours unit directly, removing the conversion
arithmetic.

Co-Authored-By: Claude <noreply@anthropic.com>
Collapse the if-seen/else-new branches so the category/group/subcategory
merge logic runs once per entry unconditionally, appending to empty lists
on first sight instead of duplicating the append logic in the else branch.

Annotate seen and entries as dict[str, Any] so ty can resolve the mixed
value types (str, list, None) in each entry dict.

Co-Authored-By: Claude <noreply@anthropic.com>
…r_inline helper

Merge the two inline-renderer implementations into a single _render_inline(children, *, html) function that handles both output modes. The original public functions become one-line wrappers so all dispatch logic lives in one place. Also aligns html_inline handling: the html=True path now escapes the raw content instead of silently dropping it in the plain-text path.

Co-Authored-By: Claude <noreply@anthropic.com>
Eliminate the redundant _find_link_deep precheck by merging the two
walks over inline.children into one loop that simultaneously locates
the link and records its top-level index.

Co-Authored-By: Claude <noreply@anthropic.com>
Replace os.path.join + manual open() with Path(__file__).resolve().parents[2]
and Path.read_text() for locating and reading README.md.

Co-Authored-By: Claude <noreply@anthropic.com>
Override font-size to var(--text-lg) inside .sponsor-meta so the
Sponsors heading is larger, while the shared .section-label class
remains --text-sm everywhere else.

Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: Claude <noreply@anthropic.com>
…ration

Swap the border-bottom + padding-bottom fake underline on .sponsor-become
for a native text-decoration underline with text-underline-offset so the
line hugs the text at the same distance as the hero @vinta/@JinyangWang27
links, rather than sitting a fixed 0.2rem gap away.

Co-Authored-By: Claude <noreply@anthropic.com>
Swaps --line-strong for --accent-underline on the 'Become a sponsor'
text-decoration-color so the underline matches the tan hover underline
on project-name links like thealgorithms.

Co-Authored-By: Claude <noreply@anthropic.com>
…-line-strong at rest

Co-Authored-By: Claude <noreply@anthropic.com>
@vinta vinta merged commit cfcc564 into master Apr 19, 2026
5 checks passed
@vinta vinta deleted the chore/code-cleanup branch April 19, 2026 14:58
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.

1 participant