-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Add yt-dlp stubs #14216
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Add yt-dlp stubs #14216
Conversation
This comment has been minimized.
This comment has been minimized.
d61f3aa
to
dca5efb
Compare
This comment has been minimized.
This comment has been minimized.
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 |
768a80d
to
9386a7d
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
c85fb47
to
f75d465
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
b2beb7e
to
dbb88ac
Compare
This comment has been minimized.
This comment has been minimized.
@srittau this is ready for review. |
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]
|
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, one note below.
Also, most uses of object
should probably be Any
. For example Mapping[str, object]
, where the type depends on the key, the type should be Mapping[str, Any]
. Similar in other cases where *args
arguments are marked as object
. object
is only applicable for argument types, if literally any object can be used in all situations. These are fairly rare. But please note that Any
must be documented, unless it's obvious why Any
was used (as is the case for Mapping[str, Any]
).
Cases where object
is appropriate:
- Return types of callables, where the returned value is ignored.
- Cases where the arguments are passed to
str()
or a similar function that can handle all objects.
@type_check_only | ||
class _RetrySleepFunctions(TypedDict): | ||
default: NotRequired[Callable[[int], int]] | ||
file_access: NotRequired[Callable[[int], int]] | ||
fragment: NotRequired[Callable[[int], int]] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's easier and more readable to just use:
@type_check_only | |
class _RetrySleepFunctions(TypedDict): | |
default: NotRequired[Callable[[int], int]] | |
file_access: NotRequired[Callable[[int], int]] | |
fragment: NotRequired[Callable[[int], int]] | |
@type_check_only | |
class _RetrySleepFunctions(TypedDict, total=False): | |
default: Callable[[int], int] | |
file_access: Callable[[int], int] | |
fragment: Callable[[int], int] |
Also applies to the TypedDicts below.
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:
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: