Skip to content

After upgrade to 4.0.1+ dict validation crushed ValueError: not enough values to unpack #373

@mrquokka

Description

@mrquokka

Things to check first

  • I have searched the existing issues and didn't find my bug already reported there

  • I have checked that my bug is still present in the latest release

Typeguard version

4.0.1+

Python version

3.10, 3.11

What happened?

value = {'RootClass__name': '1А', 'type': 'NominalCurrent'}, origin_type = <class 'dict'>
args = (<class 'str'>,), memo = <typeguard.TypeCheckMemo object at 0x7f22f1b47dc0>

    def check_mapping(
        value: Any,
        origin_type: Any,
        args: tuple[Any, ...],
        memo: TypeCheckMemo,
    ) -> None:
        if origin_type is Dict or origin_type is dict:
            if not isinstance(value, dict):
                raise TypeCheckError("is not a dict")
        if origin_type is MutableMapping or origin_type is collections.abc.MutableMapping:
            if not isinstance(value, collections.abc.MutableMapping):
                raise TypeCheckError("is not a mutable mapping")
        elif not isinstance(value, collections.abc.Mapping):
            raise TypeCheckError("is not a mapping")
    
        if args:
>           key_type, value_type = args
E           ValueError: not enough values to unpack (expected 2, got 1)

/work/envs/beta/lib/python3.10/site-packages/typeguard/_checkers.py:220: ValueError
====================================== short test summary info ======================================
FAILED pytest_5_8_0_dev8.py::test_upgrade - ValueError: not enough values to unpack (expected 2, got 1)

on 4.0.0 works stable

How can we reproduce the bug?

import typing
from typeguard import typechecked


@typechecked
def upgrade(
  cimxml: dict[str, dict[str, typing.Any]],
  files_by_container: dict[
    str, dict[str, str | bytes | dict[str, typing.Any] | list[typing.Any]]
  ],
) -> None:
  ...


upgrade(
  {"123": {"RootClass__name": "1А", "type": "NominalCurrent"}},
  {"folder_1": {"file_1": "123"}},
)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions