Skip to content

Add yt-dlp stubs#14216

Merged
srittau merged 13 commits into
python:mainfrom
Tatsh:yt-dlp
Jul 26, 2025
Merged

Add yt-dlp stubs#14216
srittau merged 13 commits into
python:mainfrom
Tatsh:yt-dlp

Conversation

@Tatsh

@Tatsh Tatsh commented Jun 3, 2025

Copy link
Copy Markdown
Contributor

Porting over from Tatsh/yt-dlp-types.

Upstream is unlikely to have full types any time soon. Though it may seem like an insular project, there is utility in using yt-dlp outside as I do in some of my projects. Examples:

  • Use yt-dlp in addition to other code when archiving a site (yt-dlp does a good job collecting metadata with the videos)
  • Use yt-dlp but write an extractor you do not wish to contribute to yt-dlp (added via YoutubeDL.add_info_extractor()).

Private methods are included in yt_dlp.extractor.common.InfoExtractor because it is normal to extend this class and override them.

There is no intention to stub all the different extractors and post-processors. Generally they are only called by yt-dlp's 'main'.

Deprecated functions and methods are generally not included.

Once accepted I will deprecate and archive yt-dlp-types on Github and on PyPI.

cc @Sky-NiniKo @thcrt

Usages:

@github-actions

This comment has been minimized.

@Tatsh
Tatsh force-pushed the yt-dlp branch 2 times, most recently from d61f3aa to dca5efb Compare June 4, 2025 00:07
@github-actions

This comment has been minimized.

@thcrt

thcrt commented Jun 5, 2025

Copy link
Copy Markdown

Cheers for cc-ing me, appreciate it. It would indeed be nice to have the stubs maintained in typeshed and hence more easily discoverable for devs calling yt-dlp directly.

@Tatsh
Tatsh force-pushed the yt-dlp branch 4 times, most recently from 768a80d to 9386a7d Compare June 7, 2025 06:11
@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@Tatsh
Tatsh force-pushed the yt-dlp branch 3 times, most recently from c85fb47 to f75d465 Compare June 7, 2025 08:58
@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@srittau

srittau commented Jul 26, 2025

Copy link
Copy Markdown
Collaborator

Unfortunately, there are now a few stubtest errors, possibly due a new yt-dlp release in the meantime: https://github.com/python/typeshed/actions/runs/16541009423/job/46782207654?pr=14216

Comment thread stubs/yt-dlp/METADATA.toml Outdated
srittau added a commit to typeshed-internal/stub_uploader that referenced this pull request Jul 26, 2025
https://pypi.org/project/websockets/

websockets is a foundational library for full HTTP support, used by many
other trusted libraries with ~80.000.000 downloads per months.

Required for python/typeshed#14216
@srittau

srittau commented Jul 26, 2025

Copy link
Copy Markdown
Collaborator

typeshed-internal/stub_uploader#177 will fix the stub uploader problem.

@github-actions

This comment has been minimized.

@Tatsh

Tatsh commented Jul 26, 2025

Copy link
Copy Markdown
Contributor Author

This is ready for review again. I replaced most **kwargs: Any with the actual keyword arguments but not in the case of the subprocess.Popen extension since that would involve copying a ton of overloads and I feel that outside of yt-dlp it is not going to be used.

@github-actions

Copy link
Copy Markdown
Contributor

Diff from mypy_primer, showing the effect of this PR on open source code:

core (https://github.com/home-assistant/core)
+ homeassistant/components/media_extractor/__init__.py:63: error: Incompatible types (expression has type "Logger", TypedDict item "logger" has type "_LoggerProtocol")  [typeddict-item]
+ homeassistant/components/media_extractor/__init__.py:63: note: "Logger" is missing following "_LoggerProtocol" protocol members:
+ homeassistant/components/media_extractor/__init__.py:63: note:     stderr, stdout
+ homeassistant/components/media_extractor/__init__.py:63: note: Following member(s) of "Logger" have conflicts:
+ homeassistant/components/media_extractor/__init__.py:63: note:     Expected:
+ homeassistant/components/media_extractor/__init__.py:63: note:         def warning(self, message: str, *, once: bool = ..., only_once: bool = ...) -> None
+ homeassistant/components/media_extractor/__init__.py:63: note:     Got:
+ homeassistant/components/media_extractor/__init__.py:63: note:         def warning(self, msg: object, *args: object, exc_info: bool | tuple[type[BaseException], BaseException, TracebackType | None] | tuple[None, None, None] | BaseException | None = ..., stack_info: bool = ..., stacklevel: int = ..., extra: Mapping[str, object] | None = ...) -> None
+ homeassistant/components/media_extractor/__init__.py:186: error: Argument 1 to "YoutubeDL" has incompatible type "dict[str, object]"; expected "_Params | None"  [arg-type]
+ homeassistant/components/media_extractor/__init__.py:196: error: TypedDict "_InfoDict" has no key "entries"  [typeddict-item]
+ homeassistant/components/media_extractor/__init__.py:215: error: TypedDict "_InfoDict" has no key "extractor"  [typeddict-item]
+ homeassistant/components/media_extractor/__init__.py:216: error: Argument 1 to "get_best_stream_youtube" has incompatible type "list[dict[str, Any]] | None"; expected "list[dict[str, Any]]"  [arg-type]
+ homeassistant/components/media_extractor/__init__.py:217: error: Argument 1 to "get_best_stream" has incompatible type "list[dict[str, Any]] | None"; expected "list[dict[str, Any]]"  [arg-type]

@Tatsh
Tatsh requested a review from srittau July 26, 2025 19:15
@github-actions

Copy link
Copy Markdown
Contributor

Diff from mypy_primer, showing the effect of this PR on open source code:

core (https://github.com/home-assistant/core)
+ homeassistant/components/media_extractor/__init__.py:63: error: Incompatible types (expression has type "Logger", TypedDict item "logger" has type "_LoggerProtocol")  [typeddict-item]
+ homeassistant/components/media_extractor/__init__.py:63: note: "Logger" is missing following "_LoggerProtocol" protocol members:
+ homeassistant/components/media_extractor/__init__.py:63: note:     stderr, stdout
+ homeassistant/components/media_extractor/__init__.py:63: note: Following member(s) of "Logger" have conflicts:
+ homeassistant/components/media_extractor/__init__.py:63: note:     Expected:
+ homeassistant/components/media_extractor/__init__.py:63: note:         def warning(self, message: str, *, once: bool = ..., only_once: bool = ...) -> None
+ homeassistant/components/media_extractor/__init__.py:63: note:     Got:
+ homeassistant/components/media_extractor/__init__.py:63: note:         def warning(self, msg: object, *args: object, exc_info: bool | tuple[type[BaseException], BaseException, TracebackType | None] | tuple[None, None, None] | BaseException | None = ..., stack_info: bool = ..., stacklevel: int = ..., extra: Mapping[str, object] | None = ...) -> None
+ homeassistant/components/media_extractor/__init__.py:186: error: Argument 1 to "YoutubeDL" has incompatible type "dict[str, object]"; expected "_Params | None"  [arg-type]
+ homeassistant/components/media_extractor/__init__.py:196: error: TypedDict "_InfoDict" has no key "entries"  [typeddict-item]
+ homeassistant/components/media_extractor/__init__.py:215: error: TypedDict "_InfoDict" has no key "extractor"  [typeddict-item]
+ homeassistant/components/media_extractor/__init__.py:216: error: Argument 1 to "get_best_stream_youtube" has incompatible type "list[dict[str, Any]] | None"; expected "list[dict[str, Any]]"  [arg-type]
+ homeassistant/components/media_extractor/__init__.py:217: error: Argument 1 to "get_best_stream" has incompatible type "list[dict[str, Any]] | None"; expected "list[dict[str, Any]]"  [arg-type]

@srittau srittau left a comment

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.

LGTM and sorry for the delay in reviewing.

We just need another maintainer to review typeshed-internal/stub_uploader#177.

@srittau srittau closed this Jul 26, 2025
@srittau srittau reopened this Jul 26, 2025
@github-actions

Copy link
Copy Markdown
Contributor

Diff from mypy_primer, showing the effect of this PR on open source code:

core (https://github.com/home-assistant/core)
+ homeassistant/components/media_extractor/__init__.py:63: error: Incompatible types (expression has type "Logger", TypedDict item "logger" has type "_LoggerProtocol")  [typeddict-item]
+ homeassistant/components/media_extractor/__init__.py:63: note: "Logger" is missing following "_LoggerProtocol" protocol members:
+ homeassistant/components/media_extractor/__init__.py:63: note:     stderr, stdout
+ homeassistant/components/media_extractor/__init__.py:63: note: Following member(s) of "Logger" have conflicts:
+ homeassistant/components/media_extractor/__init__.py:63: note:     Expected:
+ homeassistant/components/media_extractor/__init__.py:63: note:         def warning(self, message: str, *, once: bool = ..., only_once: bool = ...) -> None
+ homeassistant/components/media_extractor/__init__.py:63: note:     Got:
+ homeassistant/components/media_extractor/__init__.py:63: note:         def warning(self, msg: object, *args: object, exc_info: bool | tuple[type[BaseException], BaseException, TracebackType | None] | tuple[None, None, None] | BaseException | None = ..., stack_info: bool = ..., stacklevel: int = ..., extra: Mapping[str, object] | None = ...) -> None
+ homeassistant/components/media_extractor/__init__.py:186: error: Argument 1 to "YoutubeDL" has incompatible type "dict[str, object]"; expected "_Params | None"  [arg-type]
+ homeassistant/components/media_extractor/__init__.py:196: error: TypedDict "_InfoDict" has no key "entries"  [typeddict-item]
+ homeassistant/components/media_extractor/__init__.py:215: error: TypedDict "_InfoDict" has no key "extractor"  [typeddict-item]
+ homeassistant/components/media_extractor/__init__.py:216: error: Argument 1 to "get_best_stream_youtube" has incompatible type "list[dict[str, Any]] | None"; expected "list[dict[str, Any]]"  [arg-type]
+ homeassistant/components/media_extractor/__init__.py:217: error: Argument 1 to "get_best_stream" has incompatible type "list[dict[str, Any]] | None"; expected "list[dict[str, Any]]"  [arg-type]

@srittau
srittau merged commit df8de9e into python:main Jul 26, 2025
96 of 97 checks passed
@Tatsh
Tatsh deleted the yt-dlp branch July 26, 2025 22:13
h-takeyeah added a commit to h-takeyeah/typeshed that referenced this pull request Jul 24, 2026
websockets is not imported anywhere in the stubs, and yt-dlp itself
treats it as an optional runtime dependency (falls back to None if
missing). This was likely a leftover from the initial stub PR (python#14216)
that was never cleaned up.
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.

4 participants