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

Add support for removing TypeVarDef in mypy 0.920 #3175

Merged
merged 5 commits into from Dec 18, 2021

Conversation

christianbundy
Copy link
Contributor

@christianbundy christianbundy commented Sep 5, 2021

Change Summary

Problem: While using the Pydantic plugin with Mypy 0.920 there is an error about TypeVarDef not being defined.

Solution: Add support for Mypy 0.920 without breaking compat with Mypy 0.910.

See-also: python/mypy#9951

Related issue number

Fixes #3528

Checklist

  • Unit tests for the changes exist
  • Tests pass on CI and coverage remains at 100%
  • Documentation reflects the changes where applicable
  • changes/<pull request or issue id>-<github username>.md file added describing change
    (see changes/README.md for details)
  • My PR is ready to review, please add a comment including the phrase "please review" to assign reviewers

Copy link
Member

@PrettyWood PrettyWood left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great thanks! 👍

@christianbundy
Copy link
Contributor Author

Looks like maybe this is failing tests? :/

I think the behavior of TypeVarType changed between 0.910 and master, so I'm unsure how we could support both.

@PrettyWood
Copy link
Member

Oh didn't see it was not in official release. I went too fast.
Well then I guess it's like toml vs tomli, it will need the next mypy release and we'll make this update.
You can probably close this PR and open a new one later with update mypy to ... and all the necessary changes

@christianbundy
Copy link
Contributor Author

Just pushed a commit that's passing mypy@master, but I'm still getting three errors on mypy@0.910:

pydantic/mypy.py:354: error: Too many arguments for "TypeVarType"  [call-arg]
pydantic/mypy.py:354: error: Argument 1 to "TypeVarType" has incompatible type "str"; expected "TypeVarDef"  [arg-type]
pydantic/mypy.py:654: error: List item 0 has incompatible type "TypeVarType"; expected "TypeVarLikeDef"  [list-item]

When the new version of Mypy comes out will we need to make a major version bump for this breaking change? I'm worried that this new usage of TypeVarType works on new versions of Mypy, but old versions of Mypy seem to have different behavior.

@hauntsaninja
Copy link
Contributor

hauntsaninja commented Sep 8, 2021

I believe all plugins have access to mypy version, which you could use to gate logic on.

You could also e.g. do the equivalent of:

def _get_tv_tvdef(*args):
    try:
        from mypy.types import TypeVarDef, TypeVarType
        tvdef = TypeVarDef(*args)
        tv = TypeVarType(tvdef)
        return tv, tvdef
    except ImportError:
        from mypy.types import TypeVarType
        tv = TypeVarType(*args)
        return tv, tv

self_type, tvar_def = _get_tv_tvdef(...)

Also, in case it's useful, this is the issue where mypy announces breaking changes to plugins: python/mypy#6617 (comment)

@PrettyWood PrettyWood added the deferred deferred until future release or until something else gets done label Sep 11, 2021
@hsheth2
Copy link

hsheth2 commented Dec 16, 2021

Now that mypy 0.920 has been released, I'm seeing this issue with pydantic 1.8.2:

setup.cfg:24: error: Error importing plugin "pydantic.mypy": cannot import name TypeVarDef

sileht added a commit to sileht/mergify-community that referenced this pull request Dec 16, 2021
0.920 has been released, but pydantic.mypy plugin is not compatible

cap mypy until pydantic get updated.

pydantic/pydantic#3175

Change-Id: Idd714099c176a26db873ed4cfc0187f443ddfb2e
mergify bot pushed a commit to Mergifyio/mergify that referenced this pull request Dec 16, 2021
0.920 has been released, but pydantic.mypy plugin is not compatible

cap mypy until pydantic get updated.

pydantic/pydantic#3175

Change-Id: Idd714099c176a26db873ed4cfc0187f443ddfb2e
stishkin pushed a commit to stishkin/onefuzz that referenced this pull request Dec 16, 2021
@christianbundy

This comment has been minimized.

@christianbundy
Copy link
Contributor Author

christianbundy commented Dec 16, 2021

Just pushed another commit so that this works correctly in both 0.910 and 0.920 -- please let me know if there's anything else.

stishkin added a commit to microsoft/onefuzz that referenced this pull request Dec 16, 2021
pydantic/pydantic#3528

python/mypy#6617 (comment)
pydantic/pydantic#3175 (comment)

updating mypy in build yml and requirements to 0.910

Co-authored-by: stas <statis@microsoft.com>
@christianbundy christianbundy changed the title Replace TypeVarDef with TypeVarType Add support for removing TypeVarDef in mypy 0.920 Dec 16, 2021
@samuelcolvin samuelcolvin removed the deferred deferred until future release or until something else gets done label Dec 18, 2021
@samuelcolvin samuelcolvin merged commit 49f946d into pydantic:master Dec 18, 2021
yajo added a commit to copier-org/copier that referenced this pull request Dec 19, 2021
@hughhan1
Copy link

Hey @samuelcolvin, do you have an estimate on when the next release of pydantic would be that would include this change? Thanks!

@matteosantama
Copy link

@hughhan1 pre-release candidate v1.9.0a1, which incorporates this change, was released two days ago and it looks like there are some bug reports rolling in. So things are progressing, but I suspect all these new bugs need to be smoothed out before v1.9.0 can be officially released!

yajo added a commit to copier-org/copier that referenced this pull request Jan 3, 2022
yajo added a commit to copier-org/copier that referenced this pull request Jan 3, 2022
yajo added a commit to copier-org/copier that referenced this pull request Jan 4, 2022
yajo added a commit to copier-org/copier that referenced this pull request Jan 4, 2022
yajo added a commit to copier-org/copier that referenced this pull request Jan 11, 2022
MichaelMatschiner pushed a commit to MichaelMatschiner/onefuzz that referenced this pull request Dec 26, 2022
pydantic/pydantic#3528

python/mypy#6617 (comment)
pydantic/pydantic#3175 (comment)

updating mypy in build yml and requirements to 0.910

Co-authored-by: stas <statis@microsoft.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Error importing plugin "pydantic.mypy": cannot import name TypeVarDef
7 participants