Skip to content

Commit 1bd3020

Browse files
authored
[sqlite3] Use TypeAlias for isolation_level (#14460)
1 parent 8317409 commit 1bd3020

File tree

2 files changed

+23
-20
lines changed

2 files changed

+23
-20
lines changed

stdlib/_sqlite3.pyi

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@ from sqlite3 import (
1616
ProgrammingError as ProgrammingError,
1717
Row as Row,
1818
Warning as Warning,
19+
_IsolationLevel,
1920
)
20-
from typing import Any, Final, Literal, TypeVar, overload
21+
from typing import Any, Final, TypeVar, overload
2122
from typing_extensions import TypeAlias
2223

2324
if sys.version_info >= (3, 11):
@@ -225,7 +226,7 @@ if sys.version_info >= (3, 12):
225226
database: StrOrBytesPath,
226227
timeout: float = 5.0,
227228
detect_types: int = 0,
228-
isolation_level: Literal["DEFERRED", "EXCLUSIVE", "IMMEDIATE"] | None = "DEFERRED",
229+
isolation_level: _IsolationLevel = "DEFERRED",
229230
check_same_thread: bool = True,
230231
cached_statements: int = 128,
231232
uri: bool = False,
@@ -237,7 +238,7 @@ if sys.version_info >= (3, 12):
237238
database: StrOrBytesPath,
238239
timeout: float,
239240
detect_types: int,
240-
isolation_level: Literal["DEFERRED", "EXCLUSIVE", "IMMEDIATE"] | None,
241+
isolation_level: _IsolationLevel,
241242
check_same_thread: bool,
242243
factory: type[_ConnectionT],
243244
cached_statements: int = 128,
@@ -250,7 +251,7 @@ if sys.version_info >= (3, 12):
250251
database: StrOrBytesPath,
251252
timeout: float = 5.0,
252253
detect_types: int = 0,
253-
isolation_level: Literal["DEFERRED", "EXCLUSIVE", "IMMEDIATE"] | None = "DEFERRED",
254+
isolation_level: _IsolationLevel = "DEFERRED",
254255
check_same_thread: bool = True,
255256
*,
256257
factory: type[_ConnectionT],
@@ -265,7 +266,7 @@ else:
265266
database: StrOrBytesPath,
266267
timeout: float = 5.0,
267268
detect_types: int = 0,
268-
isolation_level: Literal["DEFERRED", "EXCLUSIVE", "IMMEDIATE"] | None = "DEFERRED",
269+
isolation_level: _IsolationLevel = "DEFERRED",
269270
check_same_thread: bool = True,
270271
cached_statements: int = 128,
271272
uri: bool = False,
@@ -275,7 +276,7 @@ else:
275276
database: StrOrBytesPath,
276277
timeout: float,
277278
detect_types: int,
278-
isolation_level: Literal["DEFERRED", "EXCLUSIVE", "IMMEDIATE"] | None,
279+
isolation_level: _IsolationLevel,
279280
check_same_thread: bool,
280281
factory: type[_ConnectionT],
281282
cached_statements: int = 128,
@@ -286,7 +287,7 @@ else:
286287
database: StrOrBytesPath,
287288
timeout: float = 5.0,
288289
detect_types: int = 0,
289-
isolation_level: Literal["DEFERRED", "EXCLUSIVE", "IMMEDIATE"] | None = "DEFERRED",
290+
isolation_level: _IsolationLevel = "DEFERRED",
290291
check_same_thread: bool = True,
291292
*,
292293
factory: type[_ConnectionT],

stdlib/sqlite3/__init__.pyi

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,8 @@ _SqliteData: TypeAlias = str | ReadableBuffer | int | float | None
220220
_AdaptedInputData: TypeAlias = _SqliteData | Any
221221
# The Mapping must really be a dict, but making it invariant is too annoying.
222222
_Parameters: TypeAlias = SupportsLenAndGetItem[_AdaptedInputData] | Mapping[str, _AdaptedInputData]
223+
# Controls the legacy transaction handling mode of sqlite3.
224+
_IsolationLevel: TypeAlias = Literal["DEFERRED", "EXCLUSIVE", "IMMEDIATE"] | None
223225

224226
class _AnyParamWindowAggregateClass(Protocol):
225227
def step(self, *args: Any) -> object: ...
@@ -285,7 +287,7 @@ class Connection:
285287
def Warning(self) -> type[Warning]: ...
286288
@property
287289
def in_transaction(self) -> bool: ...
288-
isolation_level: str | None # one of '', 'DEFERRED', 'IMMEDIATE' or 'EXCLUSIVE'
290+
isolation_level: _IsolationLevel
289291
@property
290292
def total_changes(self) -> int: ...
291293
if sys.version_info >= (3, 12):
@@ -299,26 +301,26 @@ class Connection:
299301
def __init__(
300302
self,
301303
database: StrOrBytesPath,
302-
timeout: float = ...,
303-
detect_types: int = ...,
304-
isolation_level: str | None = ...,
305-
check_same_thread: bool = ...,
304+
timeout: float = 5.0,
305+
detect_types: int = 0,
306+
isolation_level: _IsolationLevel = "DEFERRED",
307+
check_same_thread: bool = True,
306308
factory: type[Connection] | None = ...,
307-
cached_statements: int = ...,
308-
uri: bool = ...,
309+
cached_statements: int = 128,
310+
uri: bool = False,
309311
autocommit: bool = ...,
310312
) -> None: ...
311313
else:
312314
def __init__(
313315
self,
314316
database: StrOrBytesPath,
315-
timeout: float = ...,
316-
detect_types: int = ...,
317-
isolation_level: str | None = ...,
318-
check_same_thread: bool = ...,
317+
timeout: float = 5.0,
318+
detect_types: int = 0,
319+
isolation_level: _IsolationLevel = "DEFERRED",
320+
check_same_thread: bool = True,
319321
factory: type[Connection] | None = ...,
320-
cached_statements: int = ...,
321-
uri: bool = ...,
322+
cached_statements: int = 128,
323+
uri: bool = False,
322324
) -> None: ...
323325

324326
def close(self) -> None: ...

0 commit comments

Comments
 (0)