Skip to content
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

Pydantic V1 doesn't support mypy V1.1.1 #5192

Closed
3 tasks done
samuelcolvin opened this issue Mar 15, 2023 · 10 comments
Closed
3 tasks done

Pydantic V1 doesn't support mypy V1.1.1 #5192

samuelcolvin opened this issue Mar 15, 2023 · 10 comments
Assignees
Labels
bug V1 Bug related to Pydantic V1.X Meta

Comments

@samuelcolvin
Copy link
Member

We are aware that Pydantic doesn't support V1.1.1 of mypy.

This is a tracking progress of fixes for this

Issues so far:

AFAIK v1.0.1 is pretty well supported by pydantic v1.10.6, if you find a problem with v1.0.1 and pydantic, please report it here.

Please don't create more issues about mypy >v1.0.1, instead comment here if you think the above issues don't cover the problem

Fix timeline

We currently working very hard on pydantic V2 and the significant complexity of pydantic V2 AND the pydantic mypy plugin means that switching back and forth between the two has a significant overhead.

Realistically we won't work on fixing the above for around a month, we will of course try to review community fixes.

My recommendation is to pin mypy==1.0.1 or earlier.

Partially related, Pydantic V2 will probably support mypy>=1.2, and we'll likely add a optional dependency group pydantic[mypy] just to constrain mypy, see python/typeshed#9771 (comment).

@hatem-goc
Copy link

In #5190 I found that version 1.10.2 of pydantic works well with mypy 1.1.1 YMMV

CasperWA added a commit to SINTEF/oteapi-optimade that referenced this issue Mar 17, 2023
Minor code base fixes:
- Fix documentation rendering for lists in API doc-strings.
- Update end2end_test.py according to updated dev tools guidelines.

Concerning mypy. Pydantic v1 and mypy are not being updated properly.
The latest working version of mypy with Pydantic v1 is v1.0.1, hence,
mypy should henceforth be fixed to this version. See
pydantic/pydantic#5192
for more information.
@dmontagu
Copy link
Contributor

dmontagu commented Mar 22, 2023

I believe all reported issues with using mypy 1.1.1 with pydantic v1 have been resolved, and fixes are included in the 1.10.7 release today. However, we don't currently run tests in CI againt mypy 1.1.1, so I'm not totally sure this is the case.

Please continue to report any issues you hit with mypy 1.1.1 (whether using pydantic v1 or v2), and I will try to address them as I can. Many of the issues tracked here were actually also issues with earlier versions of mypy and/or required fixes in v2 as well, so it's very helpful.

Also: I don't think we should "close" this issue until we have tests against mypy 1.1.1+ running in CI.

@trim21
Copy link
Contributor

trim21 commented Mar 22, 2023

I'm running mypy 1.1.1 with pydantic 1.10.7 in ci, it still failed because of pydantic, I'll create a issue with details later.

@markedwards
Copy link

markedwards commented Mar 22, 2023

This code is still not working with mypy 1.1.1 and pydantic 1.10.7:

from pydantic import BaseSettings, Field


class Settings(BaseSettings):
    foo: str = Field(..., env='foo')


settings = Settings()  # error: Missing named argument "foo" for "Settings"

@dmontagu
Copy link
Contributor

@markedwards I assume you meant to inherit from BaseSettings rather than BaseModel.

I think this is going to be impossible to resolve without using the pydantic mypy plugin due to the fact that mypy now respects the @dataclass_transform decorator (and this is important for IDE integrations), and this applies to any class that inherits from BaseModel (and therefore any class that inherits from BaseSettings).

It does appear to be working correctly if you use the pydantic mypy plugin though.

@dmontagu
Copy link
Contributor

Okay, actually, it looks like there may be a good solution: you can do

class Settings(BaseModel):
    foo: str = Field(default=..., env='foo')

this has the same runtime semantics but the @dataclass_transform will think there is a default value. In particular, I don't get mypy errors with the code written like this.

@markedwards
Copy link

@dmontagu yes, corrected the example. Actually, you're right it's working okay with the plugin, and with the modification you suggest. I had thought the plugin was enabled in my environment but it was not.

Thanks.

@dmontagu
Copy link
Contributor

Once #5167 is merged, I think we will have addressed all reported issues with pydantic and mypy 1.1.1 (in both v1 and v2).

@trim21 if you are hitting a new bug I'm definitely interested to resolve it, please create an issue and I'll do it as soon as I can.

@trim21
Copy link
Contributor

trim21 commented Mar 23, 2023

@dmontagu I've create a new issue #5259

mattwthompson added a commit to openforcefield/openff-interchange that referenced this issue Mar 23, 2023
CasperWA added a commit to SINTEF/oteapi-optimade that referenced this issue Mar 30, 2023
Use latest SINTEF/ci-cd callable workflows

Avoid TYPE_CHECKING blocks for coverage.

Minor code base fixes:
- Fix documentation rendering for lists in API doc-strings.
- Update end2end_test.py according to updated dev tools guidelines.

Concerning mypy. Pydantic v1 and mypy are not being updated properly.
The latest working version of mypy with Pydantic v1 is v1.0.1, hence,
mypy should henceforth be fixed to this version. See
pydantic/pydantic#5192
for more information.

Create DLite entities for OPTIMADE Structures.
Implement DLite parser for OPTIMADE.
Implement support for DLite in the Resource strategy.
mvdbeek added a commit to mvdbeek/pulsar that referenced this issue Apr 6, 2023
mvdbeek added a commit to mvdbeek/pulsar that referenced this issue Apr 6, 2023
@dmontagu dmontagu self-assigned this Apr 28, 2023
@dmontagu
Copy link
Contributor

dmontagu commented May 8, 2023

I'm going to close this now, though will still note that I won't be surprised if there are issues.

In general, for new versions of mypy, our goal will be to support them in v2 and backport fixes as best we can, but make no promises that we will maintain the integration of pydantic v1 with future mypy versions.

@dmontagu dmontagu closed this as completed May 8, 2023
mikemhenry added a commit to mikemhenry/openff-interchange that referenced this issue Feb 16, 2024
mattwthompson added a commit to openforcefield/openff-interchange that referenced this issue Feb 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug V1 Bug related to Pydantic V1.X Meta
Projects
None yet
Development

No branches or pull requests

5 participants