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 python 3.10 support #2885

Merged
merged 17 commits into from Jul 19, 2021
Merged

Add python 3.10 support #2885

merged 17 commits into from Jul 19, 2021

Conversation

PrettyWood
Copy link
Member

@PrettyWood PrettyWood commented Jun 6, 2021

Change Summary

Python 3.10.0b2 is out. Maintainers are invited to try it out. I reckon adding it in the CI doesn't hurt!

ℹ️ I invite you to read this commit by commit, which should make the review trivial

Related issue number

closes #2607
closes #2786
closes #2787

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

Error with 3.10
> DeprecationWarning: accessing one member from another is not supported
error with python 3.10
> DeprecationWarning: The distutils package is deprecated and slated
> for removal in Python 3.12.
> Use setuptools or check PEP 632 for potential alternatives
`|` operator has origin `types.Union` (and not `typing.Union`)
change from basic `__init__` to `test_hashable_required.<locals>.MyDataclass.__init__()` (with `__qualname__`)
With python 3.10, calling it results in
> DeprecationWarning: There is no current event loop
For now it can not be compiled.
Let's just skip the check on linux for now instead of tuning the CI pipeline
@PrettyWood PrettyWood force-pushed the support-3.10 branch 2 times, most recently from efad94a to 358ded3 Compare June 7, 2021 09:00
@PrettyWood
Copy link
Member Author

Hey @samuelcolvin
Since 3.10 was possibly a game breaker for pydantic, I reckon it's a good idea to check everything works as expected as soon as possible.
Quoting the python release itself

We strongly encourage maintainers of third-party Python projects to test with 3.10 during the beta phase

Reading this PR commit by commit should be trivial. The main thing is that I extracted BaseConfig and Extra in a dedicated module to make checks on enum values clean (only import this module instead of the whole main one)
Please review and tell me what you think 🙇

@PrettyWood PrettyWood marked this pull request as ready for review June 7, 2021 09:15
Copy link
Member

@samuelcolvin samuelcolvin left a comment

Choose a reason for hiding this comment

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

This looks great, pretty much ready to merge.

Can you just confirm what's changed in config.py vs. main.py?

pydantic/config.py Show resolved Hide resolved
@samuelcolvin samuelcolvin merged commit 4a54f39 into pydantic:master Jul 19, 2021
@samuelcolvin
Copy link
Member

Thanks so much.

Sorry for the slow responses. New baby, new job, no sleep, no open source for a little while.

@tirkarthi
Copy link

Just to add enum repr related changes were reverted in Python 3.10 after discussion : https://mail.python.org/archives/list/python-dev@python.org/thread/ZMC67QA2JVQJSWSFWRS6IM6ZX4EK277G/#LSTMFAPSPD3BGZ4D6HQFODXZVB3PLYKF

@PrettyWood
Copy link
Member Author

PrettyWood commented Jul 19, 2021

Congrats @samuelcolvin for the baby I didnt' know!
And thanks @tirkarthi for the info.
We (you, I, or anyone else) can just open another PR with 3.10.0b4 and revert b1c8d9e.
I reckon the rest should not be impacted 🤔

Update: done in #3000

@PrettyWood PrettyWood deleted the support-3.10 branch July 19, 2021 13:47
sthagen added a commit to sthagen/pydantic-pydantic that referenced this pull request Jul 19, 2021
import types

def is_union(tp: Type[Any]) -> bool:
return tp is Union or tp is types.Union

Choose a reason for hiding this comment

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

Is this a typo? shouldn't types.Union be types.UnionType?

https://docs.python.org/3.10/library/types.html#types.UnionType

Copy link
Member Author

Choose a reason for hiding this comment

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

They changed between last beta and first RC.
#3085

Choose a reason for hiding this comment

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

Thanks, hope this could be merged soon.

Copy link
Member Author

Choose a reason for hiding this comment

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

I will soon. But it will be part of v1.9 most likely
Adding python 3.10 was mostly for CI and to ensure it will still work once out.
But I don't expect people to use 3.10 for production already since it is not stable yet


@pytest.mark.skipif(sys.version_info < (3, 10), reason='need 3.10 version')
def test_new_union_origin():
"""On 3.10+, origin of `int | str` is `types.Union`, not `typing.Union`"""

Choose a reason for hiding this comment

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

Same here

@rmzr7
Copy link

rmzr7 commented Oct 6, 2021

@samuelcolvin when will this be released?

@samuelcolvin
Copy link
Member

Hopefully soon.

I have a lot on at the moment.

@m10d
Copy link

m10d commented Apr 17, 2022

commenting here looking for advice from those familiar with the py3.10 changes. We recently had to upgrade from python3.8->3.10. However, we encountered a pydantic bug (#3896) that blocks us from upgrading pydantic to 1.9.0 - which I understand per the title here is the only version to officially support python3.10. remaining on pydantic==1.7.4 is the only workaround I am aware of. A comment from samuel on that bug indicates its not trivial / won't likely be resolved very soon.

We use pydantic for all serialization & deserialization for json input to and output from our api (and offline for schema & tool generation). While our automated testing IS somewhat basic, both our unit and api-level full system tests are passing with python3.10 + pydantic==1.7.4.

my question is - any advice on common edge cases we should be aware of or add testing for, to (attempt to) verify this pair of versions will not bite us? I've read the linked issues and I don't believe they affect our specific use of pydantic, but 3.10 has some significant changes from 3.8. Any advise or landmines would be greatly appreciated.

@samuelcolvin
Copy link
Member

Best way to speedup a resolution and the release of 1.9.1 world be if you could submit a bugfix for #3896.

Otherwise I'll look at it soon.

@m10d
Copy link

m10d commented Apr 18, 2022

could submit a bugfix for #3896.

You may have struck some fear into my heart with your comment on #3896 :)

"bug deep in schema.py I doubt there's an easy fix I'm afraid." -SC

If you take an initial look, and it's something suited for a new contributor, I might be able to dig in. A deep dive is not in the cards for me at this movement, unfortunately. Thank you for your replies, pydantic has long been a very helpful library.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment