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
mypy "Explicit "Any" is not allowed" error when extending BaseModel
#9373
Comments
class Foo(BaseModel): # no error
model_config = ConfigDict(extra="forbid") however, the mypy plugin does not seem to work when the config comes from a variable: from pydantic import BaseModel, ConfigDict
default_config = ConfigDict(extra="forbid")
class Foo(BaseModel): # error: Explicit "Any" is not allowed (no-any-explicit)
model_config = default_config edit: actually, even with class Foo(BaseModel): # error
model_config = ConfigDict(extra="forbid")
foo: int # error goes away if you remove this edit 2: seems like configuring the mypy plugin with these options fixes it: [tool.pydantic-mypy]
init_forbid_extra = true
init_typed = true |
Hmm, thanks for reporting this. @dmontagu might have a better idea of how the |
Initial Checks
Description
in my codebase, we ban the
Any
type using the--disallow-any-explicit
rule (along with all the other rules that banAny
in other contexts). when extendingBaseModel
, mypy complains with ano-any-explicit
error.this is annoying because it means we have to add a
type:ignore
comment on all of our classes that useBaseModel
.related issue: the
dataclass
decorator had the same problem (#4355), which i fixed in #4356. but i can't seem to figure out what's causing it in this case. i think it may be related to the pydantic mypy plugin?Example Code
Python, Pydantic & OS Version
The text was updated successfully, but these errors were encountered: