Skip to content

Calling dict() on av.dictionary.Dictionary object cause ValueError #2178

Closed

Description

@laggykiller

Occurs in main branch, not in previously released versions.

from av.dictionary import Dictionary
options = Dictionary({"quality": "95"})
dict(options)

Would cause ValueError: dictionary update sequence element #0 has length 7; 2 is required

Practically, this would cause error here:

self.options = dict(options)

Activity

  1. laggykiller commented on Mar 5, 2026

    @laggykiller
    ContributorAuthor

    According to https://github.com/python/typeshed/blob/main/stdlib/builtins.pyi, python builtin dict() has multiple __init__() methods, notably the following:

    class dict(MutableMapping[_KT, _VT]):
        @overload
        def __init__(self, map: SupportsKeysAndGetItem[_KT, _VT], /) -> None: ...
        @overload
        def __init__(self, iterable: Iterable[tuple[_KT, _VT]], /) -> None: ...

    and SupportsKeysAndGetItem is defined as:

    class SupportsKeysAndGetItem(Protocol[_KT, _VT_co]):
        def keys(self) -> Iterable[_KT]: ...
        def __getitem__(self, key: _KT, /) -> _VT_co: ...

    Since av.dictionary.Dictionary does not have keys() method, it is treated as Iterable instead of SupportsKeysAndGetItem, and python tries to create dict by iterating av.dictionary.Dictionary (__iter__() yields key only, not key-value pair)

    I propose #2179 which implements keys() method and hence solve the problem

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

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions