Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
edgarrmondragon opened this issue Feb 8, 2025 · 0 comments · Fixed by #1211

Comments

@edgarrmondragon
Copy link
Contributor

edgarrmondragon commented Feb 8, 2025

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant