Skip to content

Read-only src_dict dictionary in from_dict methods should be typed as Mapping[str, Any] #1203

Closed
@edgarrmondragon

Description

@edgarrmondragon

Describe the bug

Generated classmethod from_dict

@classmethod
def from_dict(cls: type[T], src_dict: dict[str, Any]) -> T:

should probably be annotated as

    @classmethod
    def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T:

i.e. using typing.Mapping.

This marks the input dictionary as immutable and thus mypy is OK if you pass it a TypedDict. Otherwise, it correctly complains about type-incompatibility because the method could be removing or adding keys from the dictionary.

OpenAPI Spec File

NA.

Additional context

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