-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
[PYD-143] Cannot get mypy to work with both pydantic v1.x and pydantic.v1 from v2.x #6022
Comments
I would deeply appreciate if someone looks at this issue since it blocks migration to support pydantic v2 for us. |
For what it's worth, you should be able to fix the I'm not quite sure what is going on in the first one (with the |
@dmontagu To reproduce with tox:
As to why this error is happening, I've noticed in the past that mypy doesn't like code of the form |
@dmontagu do you see how we could be of any help to help this issue to get addressed? |
Same issue with
Update:
|
@jwodder Do you think it might be something to check with |
@yarikoptic python/mypy#1393 seems to be the closest pre-existing mypy issue. |
digging through linked issues there, ran into python/mypy#1153 (comment) suggesting code pattern like if TYPE_CHECKING:
import json
else:
try:
import simplejson as json
except ImportError:
import json and thus making it specific for what interface to use during TYPE_CHECKING. Would it help us here? |
@yarikoptic That would only work here if the version of pydantic installed in the type-checking environment was fixed to either 1.x or 2.x (as the pydantic version installed determines whether to import |
Ran into the same issue trying to port code from v1 to v2 and for now have followed @yarikoptic's suggestion and am only type checking with v1. It seems like this could be done cleaner if we had one final release of the 1.x branch that ships with the v1 namespace as an alias to the top-level namespace such that we could pin pydantic to >= 1.10.x and use |
Initial Checks
main
branch, or equivalentDescription
(Originally posted as Discussion question #5971, where I was encouraged to repost as an issue)
We have several inter-dependent packages that depend on pydantic in ways that will break under v2, and we've decided to stagger the updates to these packages, including having transitional releases that import from either
pydantic.v1
(on pydantic 2.x) orpydantic
(on pydantic 1.x). Our code runs correctly with this strategy, but when we try to type-check it with mypy, things break, and I am unsure how to fix this breakage.Example Code
An example (available in full at https://github.com/jwodder/pydantic-v1v2-test): This module:
with this mypy config:
and this
tox.ini
:When tested with Python 3.11.3 on macOS 11.7.2 using mypy 1.3.0, using variously pydantic 1.10.8 and dev pydantic commit
f6479b8
, therun
anddevrun
environments succeed, but thetyping
anddevtyping
do not. Thetyping
environment fails with:and the
devtyping
environment fails with:Python, Pydantic & OS Version
PYD-143
The text was updated successfully, but these errors were encountered: