Skip to content

Remove Python 3.8 Support #11258

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

Merged
merged 21 commits into from
Jan 15, 2025
Merged

Remove Python 3.8 Support #11258

merged 21 commits into from
Jan 15, 2025

Conversation

sydney-runkle
Copy link
Contributor

@sydney-runkle sydney-runkle commented Jan 10, 2025

Includes #11257 changes (with temp bound on pydantic-extra-types).

Exciting diff here!

  • Remove documentation + packaging mentions of 3.8 as a minimum version
  • Remove use of special cases for zoneinfo imports
  • Remove pytest skips related to 3.8
  • Remove 3.8 specific workarounds
  • Import Literal, Annotated, etc from typing not typing_extensions (docs examples, too)
  • Remove use of types like typing.Dict, typing.List, etc
  • Fix an abundace of tests
  • Set ruff target version to 3.9 to enforce fixes :)

Note: not touching v1 files.

Best reviewed commit by commit, hiding whitespace. Would not recommend looking file by file.
I've commented on some of the more important / relevant changes below.

Copy link

cloudflare-workers-and-pages bot commented Jan 10, 2025

Deploying pydantic-docs with  Cloudflare Pages  Cloudflare Pages

Latest commit: e7b5413
Status: ✅  Deploy successful!
Preview URL: https://abce33e6.pydantic-docs.pages.dev
Branch Preview URL: https://3-8-removal.pydantic-docs.pages.dev

View logs

@github-actions github-actions bot added the relnotes-fix Used for bugfixes. label Jan 10, 2025
@sydney-runkle sydney-runkle added relnotes-change Used for changes to existing functionality which don't have a better categorization. and removed relnotes-fix Used for bugfixes. labels Jan 10, 2025
@sydney-runkle sydney-runkle marked this pull request as draft January 10, 2025 19:02
Copy link

codspeed-hq bot commented Jan 10, 2025

CodSpeed Performance Report

Merging #11258 will improve performances by 16.74%

Comparing 3.8-removal (e7b5413) with main (7506b1c)

🎉 Hooray! pytest-codspeed just leveled up to 3.1.2!

A heads-up, this is a breaking change and it might affect your current performance baseline a bit. But here's the exciting part - it's packed with new, cool features and promises improved result stability 🥳!
Curious about what's new? Visit our releases page to delve into all the awesome details about this new version.

Summary

⚡ 15 improvements
✅ 30 untouched benchmarks

Benchmarks breakdown

Benchmark main 3.8-removal Change
test_list_of_models_serialization 58.4 µs 53.4 µs +9.18%
test_complex_model_validation[__init__] 54.8 µs 49.4 µs +10.94%
test_complex_model_validation[model_validate] 55.2 µs 50.1 µs +10.17%
test_list_of_models_validation[__init__] 94 µs 82.1 µs +14.53%
test_list_of_models_validation[model_validate] 92.3 µs 79.1 µs +16.74%
test_nested_model_validation[__init__] 57.1 µs 51.7 µs +10.49%
test_nested_model_validation[model_validate] 54.5 µs 50.1 µs +8.88%
test_simple_model_validation[__init__] 40.4 µs 36.6 µs +10.31%
test_simple_model_validation[model_validate] 40.7 µs 38.4 µs +5.97%
test_north_star_dump_python 18.3 ms 16.8 ms +8.86%
test_north_star_json_loads 21.8 ms 19.5 ms +11.85%
test_north_star_validate_json 54 ms 49.1 ms +10.17%
test_north_star_validate_json_strict 53.8 ms 48.9 ms +10.03%
test_north_star_validate_python 45.7 ms 40.7 ms +12.33%
test_north_star_validate_python_strict 35.3 ms 31.1 ms +13.49%

Comment on lines -196 to +210
assert str(devtools.debug.format(obj)).split('\n')[1:] == [
' Obj(',
' int_attr=42,',
" str_attr='Marvin',",
' ) (Obj)',
]
if sys.version_info < (3, 11):
assert str(devtools.debug.format(obj)).split('\n')[1:] == [
' Obj(',
' int_attr=42,',
" str_attr='Marvin',",
' ) (Obj)',
]
else:
assert str(devtools.debug.format(obj)).split('\n')[1:] == [
' obj: Obj(',
' int_attr=42,',
" str_attr='Marvin',",
' ) (Obj)',
]
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This change is just related to a version bump in uv.lock. The only one of its kind in this PR.

@@ -1466,9 +1466,6 @@ class InnerModel(OuterModelA[K, V], OuterModelB[T], Generic[K, V, T]):
}


# TODO: SYDNEY - determine changes to make here (next 4 tests with 3.9 notes)


def test_generic_with_referenced_generic_type_1():
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@Viicos, I don't think I fully understand the changes you want made to these functions, perhaps you could help me out on this part? Thanks!

Copy link
Contributor

github-actions bot commented Jan 10, 2025

Coverage report

Click to see where and how coverage changed

FileStatementsMissingCoverageCoverage
(new stmts)
Lines missing
  pydantic
  dataclasses.py
  fields.py
  functional_serializers.py
  json_schema.py
  main.py
  mypy.py
  networks.py
  type_adapter.py
  types.py
  pydantic/_internal
  _core_utils.py
  _decorators.py
  _decorators_v1.py
  _discriminated_union.py
  _fields.py
  _generate_schema.py
  _generics.py
  _known_annotated_metadata.py
  _mock_val_ser.py
  _model_construction.py
  _schema_generation_shared.py
  _typing_extra.py
  _validators.py
  pydantic/experimental
  pipeline.py
  pydantic/plugin
  __init__.py
  _loader.py
Project Total  

The report is truncated to 25 files out of 36. To see the full report, please visit the workflow summary page.

This report was generated by python-coverage-comment-action

@sydney-runkle sydney-runkle changed the title Draft: Removing Python 3.8 Support Removing Python 3.8 Support Jan 11, 2025
@sydney-runkle
Copy link
Contributor Author

I'm guessing test failures are related to:

PEP 585 generic aliases don't convert args to ForwardRefs, unlike typing.List/Dict etc.

Looking into this now.

@sydney-runkle sydney-runkle changed the title Removing Python 3.8 Support Remove Python 3.8 Support Jan 14, 2025
@sydney-runkle sydney-runkle marked this pull request as ready for review January 14, 2025 09:34
@sydney-runkle sydney-runkle added the third-party-tests Add this label on a PR to trigger 3rd party tests label Jan 14, 2025
@sydney-runkle sydney-runkle reopened this Jan 14, 2025
@sydney-runkle sydney-runkle requested a review from Viicos January 14, 2025 13:59
Copy link
Member

@Viicos Viicos left a comment

Choose a reason for hiding this comment

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

Just checking: do we have a single test testing for typing.Dict/List/etc? So that we gather this as a single test, and then safely use the builtins in other tests (and we are still assured that the old constructs are supported).

@sydney-runkle
Copy link
Contributor Author

Just checking: do we have a single test testing for typing.Dict/List/etc? So that we gather this as a single test, and then safely use the builtins in other tests (and we are still assured that the old constructs are supported).

No, we should probably do this. How detailed do you think we need to be here? Ex - parametrization with forwardrefs, etc...

@sydney-runkle
Copy link
Contributor Author

Just checking: do we have a single test testing for typing.Dict/List/etc? So that we gather this as a single test, and then safely use the builtins in other tests (and we are still assured that the old constructs are supported).

Done via tests/test_types.py:test_pep585_generic_types

@sydney-runkle sydney-runkle requested a review from Viicos January 15, 2025 15:01
@sydney-runkle sydney-runkle merged commit c371bd1 into main Jan 15, 2025
79 checks passed
@sydney-runkle sydney-runkle deleted the 3.8-removal branch January 15, 2025 15:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
relnotes-change Used for changes to existing functionality which don't have a better categorization. third-party-tests Add this label on a PR to trigger 3rd party tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants