Skip to content

[yt-dlp] Fix types of number parsing and formatting helpers - #16947

Open
Asimmimx wants to merge 1 commit into
python:mainfrom
Asimmimx:yt-dlp-number-helpers
Open

Asimmimx wants to merge 1 commit into
python:mainfrom
Asimmimx:yt-dlp-number-helpers

Conversation

@Asimmimx

@Asimmimx Asimmimx commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

Several helpers in yt_dlp.utils return None (or a different type) where the stubs don't allow it, e.g. parse_count("1.2M views") returns 1200000 (an int, not a str), parse_bytes("x") and str_to_int("x") return None, format_decimal_suffix(-1) returns None, and format_bytes(None) returns "N/A". This updates format_decimal_suffix, format_bytes, lookup_unit_table, parse_bytes, parse_count and str_to_int to match.

Upstream: format_decimal_suffix to parse_count, str_to_int

Prepared with AI assistance (Claude Code).

🤖 Generated with Claude Code

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions

github-actions Bot commented Dec 2, 2026

Copy link
Copy Markdown
Contributor

According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉

def lookup_unit_table(unit_table: Mapping[str, int], s: str, strict: bool = False) -> float: ...
def parse_bytes(s: str) -> int: ...
def format_decimal_suffix(num: FloatInt | None, fmt: str = "%d%s", *, factor: int = 1000) -> str | None: ...
def format_bytes(bytes: FloatInt | None) -> str: ...

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a full review, but FloatInt must not be used in new code.

This branch has not been deployed

No deployments
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