typeshed icon indicating copy to clipboard operation
typeshed copied to clipboard

Add yt-dlp stubs

Open Tatsh opened this issue 5 months ago • 17 comments

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:

  • https://github.com/Tatsh/yt-dlp-utils/blob/master/yt_dlp_utils/lib.py#L51
  • https://github.com/Tatsh/patreon-archiver/blob/master/patreon_archiver/main.py#L68 (indirect through yt-dlp-utils)

Tatsh avatar Jun 03 '25 23:06 Tatsh

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:69: error: Unexpected keyword argument "download" for "extract_info" of "YoutubeDL"  [call-arg]
+ homeassistant/components/media_extractor/__init__.py:69: error: Unexpected keyword argument "process" for "extract_info" of "YoutubeDL"  [call-arg]
+ homeassistant/components/media_extractor/__init__.py:186: error: Argument 1 to "YoutubeDL" has incompatible type "dict[str, object]"; expected "YDLOpts"  [arg-type]
+ homeassistant/components/media_extractor/__init__.py:189: error: Unexpected keyword argument "process" for "extract_info" of "YoutubeDL"  [call-arg]
+ homeassistant/components/media_extractor/__init__.py:196: error: No overload variant of "list" matches argument type "object"  [call-overload]
+ homeassistant/components/media_extractor/__init__.py:196: note: Possible overload variants:
+ homeassistant/components/media_extractor/__init__.py:196: note:     def [_T] __init__(self) -> list[_T]
+ homeassistant/components/media_extractor/__init__.py:196: note:     def [_T] __init__(self, Iterable[_T], /) -> list[_T]
+ homeassistant/components/media_extractor/__init__.py:208: error: "YoutubeDL" has no attribute "params"  [attr-defined]
+ homeassistant/components/media_extractor/__init__.py:209: error: "YoutubeDL" has no attribute "process_ie_result"  [attr-defined]

github-actions[bot] avatar Jun 04 '25 00:06 github-actions[bot]

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:69: error: Unexpected keyword argument "download" for "extract_info" of "YoutubeDL"  [call-arg]
+ homeassistant/components/media_extractor/__init__.py:69: error: Unexpected keyword argument "process" for "extract_info" of "YoutubeDL"  [call-arg]
+ homeassistant/components/media_extractor/__init__.py:186: error: Argument 1 to "YoutubeDL" has incompatible type "dict[str, object]"; expected "YDLOpts | None"  [arg-type]
+ homeassistant/components/media_extractor/__init__.py:189: error: Unexpected keyword argument "process" for "extract_info" of "YoutubeDL"  [call-arg]
+ homeassistant/components/media_extractor/__init__.py:196: error: No overload variant of "list" matches argument type "object"  [call-overload]
+ homeassistant/components/media_extractor/__init__.py:196: note: Possible overload variants:
+ homeassistant/components/media_extractor/__init__.py:196: note:     def [_T] __init__(self) -> list[_T]
+ homeassistant/components/media_extractor/__init__.py:196: note:     def [_T] __init__(self, Iterable[_T], /) -> list[_T]
+ homeassistant/components/media_extractor/__init__.py:208: error: "YoutubeDL" has no attribute "params"  [attr-defined]
+ homeassistant/components/media_extractor/__init__.py:209: error: "YoutubeDL" has no attribute "process_ie_result"  [attr-defined]

github-actions[bot] avatar Jun 04 '25 00:06 github-actions[bot]

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.

thcrt avatar Jun 05 '25 13:06 thcrt

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]

github-actions[bot] avatar Jun 07 '25 06:06 github-actions[bot]

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]

github-actions[bot] avatar Jun 07 '25 07:06 github-actions[bot]

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]

github-actions[bot] avatar Jun 07 '25 07:06 github-actions[bot]

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]

github-actions[bot] avatar Jun 07 '25 08:06 github-actions[bot]

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]

github-actions[bot] avatar Jun 07 '25 09:06 github-actions[bot]

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]

github-actions[bot] avatar Jun 07 '25 09:06 github-actions[bot]

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]

github-actions[bot] avatar Jun 07 '25 14:06 github-actions[bot]

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]

github-actions[bot] avatar Jun 07 '25 22:06 github-actions[bot]

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]

github-actions[bot] avatar Jun 07 '25 23:06 github-actions[bot]

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]

github-actions[bot] avatar Jun 08 '25 00:06 github-actions[bot]

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]

github-actions[bot] avatar Jun 08 '25 04:06 github-actions[bot]

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[object] | 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[object] | None"; expected "list[dict[str, Any]]"  [arg-type]

github-actions[bot] avatar Jun 08 '25 05:06 github-actions[bot]

@srittau this is ready for review.

Tatsh avatar Jun 08 '25 05:06 Tatsh

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[object] | 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[object] | None"; expected "list[dict[str, Any]]"  [arg-type]

github-actions[bot] avatar Jun 08 '25 05:06 github-actions[bot]

Sorry I missed the notif, but like thcrt, thanks for cc-ing me. This is indeed a good idea, and it is well executed. Fingers crossed for a quick review and a peaceful merge.

Sky-NiniKo avatar Jul 23 '25 16:07 Sky-NiniKo

Still working on replacing the Any types.

Tatsh avatar Jul 24 '25 23:07 Tatsh

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[object] | 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[object] | None"; expected "list[dict[str, Any]]"  [arg-type]

github-actions[bot] avatar Jul 25 '25 00:07 github-actions[bot]

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[object] | 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[object] | None"; expected "list[dict[str, Any]]"  [arg-type]

github-actions[bot] avatar Jul 25 '25 00:07 github-actions[bot]

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[object] | 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[object] | None"; expected "list[dict[str, Any]]"  [arg-type]

github-actions[bot] avatar Jul 25 '25 01:07 github-actions[bot]

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[object] | 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[object] | None"; expected "list[dict[str, Any]]"  [arg-type]

github-actions[bot] avatar Jul 25 '25 02:07 github-actions[bot]

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]

github-actions[bot] avatar Jul 26 '25 14:07 github-actions[bot]

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]

github-actions[bot] avatar Jul 26 '25 15:07 github-actions[bot]

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

srittau avatar Jul 26 '25 17:07 srittau

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

srittau avatar Jul 26 '25 17:07 srittau

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]

github-actions[bot] avatar Jul 26 '25 18:07 github-actions[bot]

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.

Tatsh avatar Jul 26 '25 19:07 Tatsh

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]

github-actions[bot] avatar Jul 26 '25 19:07 github-actions[bot]