Skip to content

Commit 92af074

Browse files
authored
💥 Drop support for Python 3.10 (#2139)
1 parent 89f6325 commit 92af074

23 files changed

Lines changed: 109 additions & 529 deletions

File tree

‎.github/workflows/test.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ jobs:
4545
database: mysql
4646
database-url: mysql+pymysql://sqlmodel:sqlmodel@127.0.0.1:13306/sqlmodel_test
4747
- os: ubuntu-latest
48-
python-version: "3.10"
48+
python-version: "3.11"
4949
uv-resolution: lowest-direct
5050
database: mysql
5151
database-url: mysql+pymysql://sqlmodel:sqlmodel@127.0.0.1:13306/sqlmodel_test

‎docs/advanced/datetime.md‎

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,11 @@ Let's say that each event in our application has a `created_at` field.
2121

2222
We can declare it with `datetime` and use `default_factory` to generate the current time in UTC:
2323

24-
{* ./docs_src/advanced/datetime/tutorial001_py311.py ln[1:8] hl[1,8] *}
24+
{* ./docs_src/advanced/datetime/tutorial001.py ln[1:8] hl[1,8] *}
2525

2626
/// tip
2727

28-
The [`UTC` constant](https://docs.python.org/3/library/datetime.html#datetime.UTC) is available on Python 3.11 and newer. It is an alias for `timezone.utc`.
29-
30-
For Python 3.10, expand **Other versions and variants** below the example. That version imports `timezone` and uses `datetime.now(timezone.utc)` instead.
28+
The [`UTC` constant](https://docs.python.org/3/library/datetime.html#datetime.UTC) is an alias for `timezone.utc`.
3129

3230
///
3331

@@ -39,15 +37,15 @@ Passing `datetime.now(UTC)` directly would call it immediately, when defining th
3937

4038
We can create an event without passing a value for `created_at`:
4139

42-
{* ./docs_src/advanced/datetime/tutorial001_py311.py ln[17:19] hl[18] *}
40+
{* ./docs_src/advanced/datetime/tutorial001.py ln[17:19] hl[18] *}
4341

4442
For the database column, **SQLModel** uses `UTCDateTime`, a custom SQLAlchemy type based on `DateTime(timezone=True)`. It uses native timezone support when the database provides it.
4543

4644
### Write and Read Datetimes
4745

4846
Let's save the event to `database.db` and read it back using SQLite:
4947

50-
{* ./docs_src/advanced/datetime/tutorial001_py311.py ln[11:14,21:26] hl[23:25] *}
48+
{* ./docs_src/advanced/datetime/tutorial001.py ln[11:14,21:26] hl[23:25] *}
5149

5250
The datetime goes through these steps:
5351

‎docs/tutorial/fastapi/tests.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ Now we can run the tests with `pytest` and see the results:
356356
$ uv run pytest
357357

358358
============= test session starts ==============
359-
platform linux -- Python 3.10.0, pytest-7.4.4, pluggy-1.5.0
359+
platform linux -- Python 3.11.0, pytest-7.4.4, pluggy-1.5.0
360360
rootdir: /home/user/code/sqlmodel-tutorial
361361
<b>collected 7 items </b>
362362

File renamed without changes.

‎docs_src/advanced/datetime/tutorial001_py310.py‎

Lines changed: 0 additions & 30 deletions
This file was deleted.

‎docs_src/tutorial/create_db_and_table/annotations/en/tutorial003.md‎

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,43 @@
1-
1. Import `Optional` from `typing` to declare fields that could be `None`.
2-
2. Import the things we will need from `sqlmodel`: `Field`, `SQLModel`, `create_engine`.
3-
3. Create the `Hero` model class, representing the `hero` table in the database.
1+
1. Import the things we will need from `sqlmodel`: `Field`, `SQLModel`, `create_engine`.
2+
2. Create the `Hero` model class, representing the `hero` table in the database.
43

54
And also mark this class as a **table model** with `table=True`.
65

7-
4. Create the `id` field:
6+
3. Create the `id` field:
87

9-
It could be `None` until the database assigns a value to it, so we annotate it with `Optional` (`int | None` in Python 3.10+).
8+
It could be `None` until the database assigns a value to it, so we annotate it with `int | None`.
109

1110
It is a **primary key**, so we use `Field()` and the argument `primary_key=True`.
1211

13-
5. Create the `name` field.
12+
4. Create the `name` field.
1413

15-
It is required, so there's no default value, and it's not `Optional`.
14+
It is required, so there's no default value, and it cannot be `None`.
1615

17-
6. Create the `secret_name` field.
16+
5. Create the `secret_name` field.
1817

1918
Also required.
2019

21-
7. Create the `age` field.
20+
6. Create the `age` field.
2221

2322
It is not required, the default value is `None`.
2423

2524
In the database, the default value will be `NULL`, the SQL equivalent of `None`.
2625

27-
As this field could be `None` (and `NULL` in the database), we annotate it with `Optional` (`int | None` in Python 3.10+).
26+
As this field could be `None` (and `NULL` in the database), we annotate it with `int | None`.
2827

29-
8. Write the name of the database file.
30-
9. Use the name of the database file to create the database URL.
31-
10. Create the engine using the URL.
28+
7. Write the name of the database file.
29+
8. Use the name of the database file to create the database URL.
30+
9. Create the engine using the URL.
3231

3332
This doesn't create the database yet, no file or table is created at this point, only the **engine** object that will handle the connections with this specific database, and with specific support for SQLite (based on the URL).
3433

35-
11. Put the code that creates side effects in a function.
34+
10. Put the code that creates side effects in a function.
3635

3736
In this case, only one line that creates the database file with the table.
3837

39-
12. Create all the tables that were automatically registered in `SQLModel.metadata`.
38+
11. Create all the tables that were automatically registered in `SQLModel.metadata`.
4039

41-
13. Add a main block, or "Top-level script environment".
40+
12. Add a main block, or "Top-level script environment".
4241

4342
And put some logic to be executed when this is called directly with Python, as in:
4443

@@ -58,7 +57,7 @@
5857
from app import Hero
5958
```
6059

61-
14. In this main block, call the function that creates the database file and the table.
60+
13. In this main block, call the function that creates the database file and the table.
6261

6362
This way when we call it with:
6463

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
1-
from sqlmodel import Field, SQLModel, create_engine # (2)!
1+
from sqlmodel import Field, SQLModel, create_engine # (1)!
22

33

4-
class Hero(SQLModel, table=True): # (3)!
5-
id: int | None = Field(default=None, primary_key=True) # (4)!
6-
name: str # (5)!
7-
secret_name: str # (6)!
8-
age: int | None = None # (7)!
4+
class Hero(SQLModel, table=True): # (2)!
5+
id: int | None = Field(default=None, primary_key=True) # (3)!
6+
name: str # (4)!
7+
secret_name: str # (5)!
8+
age: int | None = None # (6)!
99

1010

11-
sqlite_file_name = "database.db" # (8)!
12-
sqlite_url = f"sqlite:///{sqlite_file_name}" # (9)!
11+
sqlite_file_name = "database.db" # (7)!
12+
sqlite_url = f"sqlite:///{sqlite_file_name}" # (8)!
1313

14-
engine = create_engine(sqlite_url, echo=True) # (10)!
14+
engine = create_engine(sqlite_url, echo=True) # (9)!
1515

1616

17-
def create_db_and_tables(): # (11)!
18-
SQLModel.metadata.create_all(engine) # (12)!
17+
def create_db_and_tables(): # (10)!
18+
SQLModel.metadata.create_all(engine) # (11)!
1919

2020

21-
if __name__ == "__main__": # (13)!
22-
create_db_and_tables() # (14)!
21+
if __name__ == "__main__": # (12)!
22+
create_db_and_tables() # (13)!

‎pyproject.toml‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ name = "sqlmodel"
77
dynamic = ["version"]
88
description = "SQLModel, SQL databases in Python, designed for simplicity, compatibility, and robustness."
99
readme = "README.md"
10-
requires-python = ">=3.10"
10+
requires-python = ">=3.11"
1111
authors = [
1212
{ name = "Sebastián Ramírez", email = "tiangolo@gmail.com" },
1313
]
@@ -21,7 +21,6 @@ classifiers = [
2121
"Intended Audience :: Science/Research",
2222
"Intended Audience :: System Administrators",
2323
"Programming Language :: Python :: 3 :: Only",
24-
"Programming Language :: Python :: 3.10",
2524
"Programming Language :: Python :: 3.11",
2625
"Programming Language :: Python :: 3.12",
2726
"Programming Language :: Python :: 3.13",
@@ -83,7 +82,8 @@ tests = [
8382
"aiosqlite >=0.17.0",
8483
"alembic >=1.12.0",
8584
"black >=24.1.0",
86-
"coverage[toml] >=6.2",
85+
# Support Python 3.11+ and the configured C tracer.
86+
"coverage[toml] >=7.9.0",
8787
"dirty-equals >=0.11",
8888
"fastapi >=0.128.0",
8989
"httpx >=0.28.1",

‎sqlmodel/ext/asyncio/session.py‎

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from typing import (
33
Any,
44
TypeVar,
5+
TypeVarTuple,
56
cast,
67
overload,
78
)
@@ -17,7 +18,7 @@
1718
from sqlalchemy.sql.base import Executable as _Executable
1819
from sqlalchemy.sql.dml import UpdateBase
1920
from sqlalchemy.util.concurrency import greenlet_spawn
20-
from typing_extensions import TypeVarTuple, Unpack, deprecated
21+
from typing_extensions import deprecated
2122

2223
from ...orm.session import Session
2324
from ...sql.base import Executable
@@ -34,14 +35,14 @@ class AsyncSession(_AsyncSession):
3435
@overload
3536
async def exec(
3637
self,
37-
statement: Select[Unpack[_Ts]],
38+
statement: Select[*_Ts],
3839
*,
3940
params: Mapping[str, Any] | Sequence[Mapping[str, Any]] | None = None,
4041
execution_options: Mapping[str, Any] = util.EMPTY_DICT,
4142
bind_arguments: dict[str, Any] | None = None,
4243
_parent_execute_state: Any | None = None,
4344
_add_event: Any | None = None,
44-
) -> TupleResult[tuple[Unpack[_Ts]]]: ...
45+
) -> TupleResult[tuple[*_Ts]]: ...
4546

4647
@overload
4748
async def exec(
@@ -65,11 +66,11 @@ async def exec(
6566
bind_arguments: dict[str, Any] | None = None,
6667
_parent_execute_state: Any | None = None,
6768
_add_event: Any | None = None,
68-
) -> CursorResult[Unpack[tuple[Any, ...]]]: ...
69+
) -> CursorResult[*tuple[Any, ...]]: ...
6970

7071
async def exec(
7172
self,
72-
statement: Select[Unpack[_Ts]]
73+
statement: Select[*_Ts]
7374
| SelectOfScalar[_TSelectParam]
7475
| Executable[_TSelectParam]
7576
| UpdateBase,
@@ -80,9 +81,9 @@ async def exec(
8081
_parent_execute_state: Any | None = None,
8182
_add_event: Any | None = None,
8283
) -> (
83-
TupleResult[tuple[Unpack[_Ts]]]
84+
TupleResult[tuple[*_Ts]]
8485
| ScalarResult[_TSelectParam]
85-
| CursorResult[Unpack[tuple[Any, ...]]]
86+
| CursorResult[*tuple[Any, ...]]
8687
):
8788
if execution_options:
8889
execution_options = util.immutabledict(execution_options).union(
@@ -101,7 +102,7 @@ async def exec(
101102
_add_event=_add_event,
102103
)
103104
result_value = await _ensure_sync_result(
104-
cast(Result[Unpack[tuple[Any, ...]]], result), self.exec
105+
cast(Result[*tuple[Any, ...]], result), self.exec
105106
)
106107
return result_value # type: ignore
107108

@@ -136,7 +137,7 @@ async def execute(
136137
bind_arguments: dict[str, Any] | None = None,
137138
_parent_execute_state: Any | None = None,
138139
_add_event: Any | None = None,
139-
) -> Result[Unpack[tuple[Any, ...]]]:
140+
) -> Result[*tuple[Any, ...]]:
140141
"""
141142
🚨 You probably want to use `session.exec()` instead of `session.execute()`.
142143

‎sqlmodel/main.py‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
TypeVar,
2121
Union,
2222
cast,
23+
dataclass_transform,
2324
get_origin,
2425
overload,
2526
)
@@ -52,7 +53,7 @@
5253
from sqlalchemy.sql.schema import MetaData
5354
from sqlalchemy.sql.sqltypes import LargeBinary, Time, Uuid
5455
from sqlalchemy.types import TypeEngine
55-
from typing_extensions import dataclass_transform, deprecated
56+
from typing_extensions import deprecated
5657

5758
from ._compat import (
5859
PYDANTIC_MINOR_VERSION,

0 commit comments

Comments
 (0)