Skip to content

Commit

Permalink
Drop 3.8 support (#1604)
Browse files Browse the repository at this point in the history
  • Loading branch information
sydney-runkle authored Jan 22, 2025
1 parent e572f55 commit b426cce
Show file tree
Hide file tree
Showing 43 changed files with 648 additions and 681 deletions.
3 changes: 2 additions & 1 deletion .github/check_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"""
Check the version in Cargo.toml matches the version from `GITHUB_REF` environment variable.
"""

import os
import re
import sys
Expand All @@ -18,7 +19,7 @@ def main() -> int:
if version_ref:
version = re.sub('^refs/tags/v*', '', version_ref.lower())
else:
print(f'✖ "GITHUB_REF" env variables not found')
print('✖ "GITHUB_REF" env variables not found')
return 1

# convert from python pre-release version to rust pre-release version
Expand Down
25 changes: 9 additions & 16 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ jobs:
fail-fast: false
matrix:
python-version:
- '3.8'
- '3.9'
- '3.10'
- '3.11'
Expand Down Expand Up @@ -403,15 +402,15 @@ jobs:
- os: linux
manylinux: auto
target: armv7
interpreter: 3.8 3.9 3.10 3.11 3.12 3.13
interpreter: 3.9 3.10 3.11 3.12 3.13
- os: linux
manylinux: auto
target: ppc64le
interpreter: 3.8 3.9 3.10 3.11 3.12 3.13
interpreter: 3.9 3.10 3.11 3.12 3.13
- os: linux
manylinux: auto
target: s390x
interpreter: 3.8 3.9 3.10 3.11 3.12 3.13
interpreter: 3.9 3.10 3.11 3.12 3.13
- os: linux
manylinux: auto
target: x86_64
Expand All @@ -435,7 +434,7 @@ jobs:
target: x86_64
- os: macos
target: aarch64
interpreter: 3.8 3.9 pypy3.9 pypy3.10
interpreter: 3.9 pypy3.9 pypy3.10

# windows;
# x86_64 pypy builds are not PGO optimized
Expand All @@ -447,7 +446,7 @@ jobs:
- os: windows
target: i686
python-architecture: x86
interpreter: 3.8 3.9 3.10 3.11 3.12 3.13
interpreter: 3.9 3.10 3.11 3.12 3.13
- os: windows
target: aarch64
interpreter: 3.11 3.12 3.13
Expand Down Expand Up @@ -477,10 +476,8 @@ jobs:
with:
target: ${{ matrix.target }}
manylinux: ${{ matrix.manylinux }}
args: --release --out dist --interpreter ${{ matrix.interpreter || '3.8 3.9 3.10 3.11 3.12 3.13 pypy3.9 pypy3.10' }}
# Limit windows builds to 1.77 to keep Windows 7 support.
# FIXME: Unpin when Python 3.8 support is dropped. (3.9 requires Windows 10)
rust-toolchain: ${{ (matrix.os == 'windows' && '1.77') || 'stable' }}
args: --release --out dist --interpreter ${{ matrix.interpreter || '3.9 3.10 3.11 3.12 3.13 pypy3.9 pypy3.10' }}
rust-toolchain: stable
docker-options: -e CI

- run: ${{ (matrix.os == 'windows' && 'dir') || 'ls -lh' }} dist/
Expand All @@ -500,7 +497,7 @@ jobs:
fail-fast: false
matrix:
os: [linux, windows, macos]
interpreter: ['3.8', '3.9', '3.10', '3.11', '3.12', '3.13']
interpreter: ['3.9', '3.10', '3.11', '3.12', '3.13']
include:
# standard runners with override for macos arm
- os: linux
Expand All @@ -512,8 +509,6 @@ jobs:
runs-on: macos-latest-xlarge
exclude:
# macos arm only supported from 3.10 and up
- os: macos
interpreter: '3.8'
- os: macos
interpreter: '3.9'

Expand All @@ -531,9 +526,7 @@ jobs:
uses: dtolnay/rust-toolchain@master
with:
components: llvm-tools
# Limit windows builds to 1.77 to keep Windows 7 support.
# FIXME: Unpin when Python 3.8 support is dropped. (3.9 requires Windows 10)
toolchain: ${{ (matrix.os == 'windows' && '1.77') || 'stable' }}
toolchain: stable

- name: Build PGO wheel
id: pgo-wheel
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ except ValidationError as e:

You'll need rust stable [installed](https://rustup.rs/), or rust nightly if you want to generate accurate coverage.

With rust and python 3.8+ installed, compiling pydantic-core should be possible with roughly the following:
With rust and python 3.9+ installed, compiling pydantic-core should be possible with roughly the following:

```bash
# clone this repo or your fork
Expand Down
27 changes: 13 additions & 14 deletions generate_self_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@
from collections.abc import Callable
from datetime import date, datetime, time, timedelta
from pathlib import Path
from typing import TYPE_CHECKING, Any, Dict, ForwardRef, List, Pattern, Set, Type, Union
from re import Pattern
from typing import TYPE_CHECKING, Any, ForwardRef, Union

from typing_extensions import TypedDict, get_args, get_origin, is_typeddict

TypingUnionType = Type[Union[str, int]]
TypingUnionType = type[Union[str, int]]

try:
from types import UnionType as TypesUnionType
Expand Down Expand Up @@ -69,17 +70,17 @@ def get_schema(obj: Any, definitions: dict[str, core_schema.CoreSchema]) -> core
expected = all_literal_values(obj)
assert expected, f'literal "expected" cannot be empty, obj={obj}'
return {'type': 'literal', 'expected': expected}
elif issubclass(origin, List):
elif issubclass(origin, list):
return {'type': 'list', 'items_schema': get_schema(obj.__args__[0], definitions)}
elif issubclass(origin, Set):
elif issubclass(origin, set):
return {'type': 'set', 'items_schema': get_schema(obj.__args__[0], definitions)}
elif issubclass(origin, Dict):
elif issubclass(origin, dict):
return {
'type': 'dict',
'keys_schema': get_schema(obj.__args__[0], definitions),
'values_schema': get_schema(obj.__args__[1], definitions),
}
elif issubclass(origin, Type):
elif issubclass(origin, type):
# can't really use 'is-instance' since this is used for the class_ parameter of 'is-instance' validators
return {'type': 'any'}
elif origin in (Pattern, re.Pattern):
Expand All @@ -90,7 +91,7 @@ def get_schema(obj: Any, definitions: dict[str, core_schema.CoreSchema]) -> core
raise TypeError(f'Unknown type: {obj!r}')


def tagged_union(std_union_schema: Dict[str, Any], discriminator_key: str, ref: str | None = None) -> Dict[str, Any]:
def tagged_union(std_union_schema: dict[str, Any], discriminator_key: str, ref: str | None = None) -> dict[str, Any]:
"""
Build a tagged union schema from a standard union schema.
"""
Expand Down Expand Up @@ -134,13 +135,13 @@ def type_dict_schema( # noqa: C901
if 'CoreSchema' == fr_arg or re.search('[^a-zA-Z]CoreSchema', fr_arg):
if fr_arg == 'CoreSchema':
schema = schema_ref_validator
elif fr_arg == 'List[CoreSchema]':
elif fr_arg == 'list[CoreSchema]':
schema = {'type': 'list', 'items_schema': schema_ref_validator}
elif fr_arg == 'Dict[str, CoreSchema]':
elif fr_arg == 'dict[str, CoreSchema]':
schema = {'type': 'dict', 'keys_schema': {'type': 'str'}, 'values_schema': schema_ref_validator}
elif fr_arg == 'Dict[Hashable, CoreSchema]':
elif fr_arg == 'dict[Hashable, CoreSchema]':
schema = {'type': 'dict', 'keys_schema': {'type': 'any'}, 'values_schema': schema_ref_validator}
elif fr_arg == 'List[Union[CoreSchema, Tuple[CoreSchema, str]]]':
elif fr_arg == 'list[Union[CoreSchema, tuple[CoreSchema, str]]]':
schema = {
'type': 'list',
'items_schema': {
Expand Down Expand Up @@ -193,9 +194,7 @@ def all_literal_values(type_: type[core_schema.Literal]) -> list[any]:


def eval_forward_ref(type_: Any) -> Any:
if sys.version_info < (3, 9):
return type_._evaluate(core_schema.__dict__, None)
elif sys.version_info < (3, 12, 4):
if sys.version_info < (3, 12, 4):
return type_._evaluate(core_schema.__dict__, None, recursive_guard=set())
else:
return type_._evaluate(core_schema.__dict__, None, type_params=set(), recursive_guard=set())
Expand Down
10 changes: 7 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ build-backend = 'maturin'
[project]
name = 'pydantic_core'
description = "Core functionality for Pydantic validation and serialization"
requires-python = '>=3.8'
requires-python = '>=3.9'
authors = [
{name = 'Samuel Colvin', email = '[email protected]'}
]
Expand All @@ -17,7 +17,6 @@ classifiers = [
'Programming Language :: Python',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3 :: Only',
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9',
'Programming Language :: Python :: 3.10',
'Programming Language :: Python :: 3.11',
Expand Down Expand Up @@ -76,6 +75,7 @@ linting = [
'pyright',
'ruff',
'mypy',
'pyupgrade',
]
wasm = [
'typing_extensions',
Expand All @@ -101,16 +101,20 @@ features = ["pyo3/extension-module"]

[tool.ruff]
line-length = 120
target-version = 'py39'

[tool.ruff.lint]
extend-select = ['Q', 'RUF100', 'C90', 'I']
extend-select = ['Q', 'RUF100', 'C90', 'I', 'UP']
extend-ignore = [
'E721', # using type() instead of isinstance() - we use this in tests
]
flake8-quotes = {inline-quotes = 'single', multiline-quotes = 'double'}
mccabe = { max-complexity = 13 }
isort = { known-first-party = ['pydantic_core', 'tests'] }

[tool.ruff.lint.pyupgrade]
keep-runtime-typing = true

[tool.ruff.format]
quote-style = 'single'

Expand Down
Loading

0 comments on commit b426cce

Please sign in to comment.