yt-dlp: incorrect visibility on parameters #16331
Copy link
Copy link
Open
Description
_Params should be public. Submitting a normal dict as a file will mismatch with the TypedDict because the type-checker will infer dict[str,bool] instead of _Params. See the example snippet:
def fetch_channel_info(channel: str) -> tuple[str, str, list[str]]:
"""Return (channel_id, channel_handle, video_ids)."""
opts = {"quiet": True, "extract_flat": True}
with yt_dlp.YoutubeDL(opts) as ydl:
info = ydl.extract_info(channel, download=False)which results in
├╴E Argument of type "dict[str, bool]" cannot be assigned to parameter "params" of type "_Params | None" in function "__init__"
│ Type "dict[str, bool]" is not assignable to type "_Params | None"
│ "dict[str, bool]" is not assignable to "_Params"
│ "dict[str, bool]" is not assignable to "None" basedpyright (reportArgumentType) [48, 27]Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels
Activity
[-]yt-dlp: Incorrect visibility on parameters[/-][+]yt-dlp: incorrect visibility on parameters[/+]donbarbos commentedon Sep 6, 2026
Hi! You can import
_Paramslike this (viaTYPE_CHECKING,_Paramsis not present at runtime):The issue isn't really with the name. The leading
_mostly indicates that this type doesn't exist at runtime.The problem is more likely related to the type checker being unable to narrow the type of the dictionary. When you create the dictionary, it is inferred as
dict[str, bool]. You can use either of the following approaches to ensure that the type is correct:BassArt1 commentedon Oct 24, 2026
Neither of these options work in many use cases.
The first makes the type checker complain about
_Paramsbeing private:The second works but is simply not practicle in many use cases.
P.S. For now I'm dealing with this problem by importing
_Paramsand ignoring the error:BassArt1 commentedon Oct 24, 2026
Nvm, this was fixed by adding a public
YoutubeDLOptionsinterface in 778a456