python / python/mypy

mypy 1.7.0 results in new [misc] type errors with pydantic usage

Open
#16,454 6 comments 5 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug topic-disallow-any
Dominant language
Python
Stars
20.6k
Forks
3.3k
PR merge metrics
PR metrics pending

Description

I was asked to file a bug with more details; it's possible that the behavior is not as much a bug as increased strictness, but given that it impacts a widely used library, I wanted to share (and ask for recommendations on how proceed since manually ignoring this issue across many projects is going to be tedious).

Minimal program:

Minimal setup:

% python --version
Python 3.12.0

% python3 -m venv .venv
% source .venv/bin/activate
% pip install -U pip mypy pydantic
% pip freeze
annotated-types==0.6.0
mypy==1.7.0
mypy-extensions==1.0.0
pydantic==2.4.2
pydantic_core==2.10.1
typing_extensions==4.8.0

% echo "from pydantic import BaseModel" >> example.py
% echo >> example.py
% echo "class Foo(BaseModel):" >> example.py
% echo "    pass" >> example.py

% mypy --disallow-any-explicit --disallow-any-decorated example.py
example.py:3: error: Explicit "Any" is not allowed  [misc]
example.py:3: error: Type of decorated function contains type "Any" ("Callable[[DefaultNamedArg(dict[str, Any] | None, '__pydantic_extra__'), DefaultNamedArg(set[str], '__pydantic_fields_set__'), DefaultNamedArg(dict[str, Any] | None, '__pydantic_private__')], None]")  [misc]
Found 2 errors in 1 file (checked 1 source file)

These errors are not reproducible with mypy 1.6.1

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the report from example.py with Python 3.12, pydantic 2.4.2, and mypy 1.7.0 using the shown command, then compare it with mypy 1.6.1. Trace the changed type-checking behavior and establish whether the [misc] errors are a regression or expected strictness; done means a documented resolution or confirmed fix.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
devtools
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.