Skip to content

yt-dlp: incorrect visibility on parameters #16331

Description

@mahyarmirrashed

_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]

Activity

  1. changed the title [-]yt-dlp: Incorrect visibility on parameters[/-] [+]yt-dlp: incorrect visibility on parameters[/+] on Sep 1, 2026
  2. donbarbos commented on Sep 6, 2026

    @donbarbos
    Contributor

    Hi! You can import _Params like this (via TYPE_CHECKING, _Params is not present at runtime):

    from typing import TYPE_CHECKING
    
    if TYPE_CHECKING:
        from yt_dlp import _Params

    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:

    # Annotate the variable:
    opts: _Params = {"quiet": True, "extract_flat": True}
    
    # Or use an inline dict:
    with yt_dlp.YoutubeDL({"quiet": True, "extract_flat": True}) as ydl:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions