Skip to content

Commit

Permalink
Fix type annotation of ModelMetaclass.__prepare__
Browse files Browse the repository at this point in the history
During class creation, the namespace returned by `__prepare__` is
populated when the class body is executed. Therefore, it must be
mutable.

The previous, incorrect annotation was fixed in the typeshed in
python/typeshed#11093
  • Loading branch information
slanzmich committed Dec 5, 2023
1 parent 20c0c6d commit bc83af9
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions pydantic/_internal/_model_construction.py
Expand Up @@ -8,7 +8,7 @@
from abc import ABCMeta
from functools import partial
from types import FunctionType
from typing import Any, Callable, Generic, Mapping
from typing import Any, Callable, Generic, MutableMapping

import typing_extensions
from pydantic_core import PydanticUndefined, SchemaSerializer
Expand Down Expand Up @@ -216,7 +216,7 @@ def __getattr__(self, item: str) -> Any:
raise AttributeError(item)

@classmethod
def __prepare__(cls, *args: Any, **kwargs: Any) -> Mapping[str, object]:
def __prepare__(cls, *args: Any, **kwargs: Any) -> MutableMapping[str, object]:
return _ModelNamespaceDict()

def __instancecheck__(self, instance: Any) -> bool:
Expand Down

0 comments on commit bc83af9

Please sign in to comment.