Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit fb6d8ef

Browse files
Remove TypeAlias annotations and handle Literal properly
1 parent 7528e6d commit fb6d8ef

File tree

5 files changed

+43
-42
lines changed

5 files changed

+43
-42
lines changed

‎asyncpg/compat.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,11 @@
1313

1414
if sys.version_info >= (3, 8):
1515
from typing import (
16-
Literal as Literal,
1716
Protocol as Protocol,
1817
TypedDict as TypedDict
1918
)
2019
else:
2120
from typing_extensions import ( # noqa: F401
22-
Literal as Literal,
2321
Protocol as Protocol,
2422
TypedDict as TypedDict
2523
)

‎asyncpg/connect_utils.py

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,14 @@
2121
import sys
2222
import time
2323
import typing
24-
import typing_extensions
2524
import urllib.parse
2625
import warnings
2726

2827
# Work around https://github.com/microsoft/pyright/issues/3012
2928
if sys.version_info >= (3, 8):
30-
from typing import Final
29+
from typing import Final, Literal
3130
else:
32-
from typing_extensions import Final
31+
from typing_extensions import Final, Literal
3332

3433
from . import compat
3534
from . import exceptions
@@ -52,30 +51,30 @@
5251
_RecordT = typing.TypeVar('_RecordT', bound=protocol.Record)
5352
_SSLModeT = typing.TypeVar('_SSLModeT', bound='SSLMode')
5453

55-
_TPTupleType: typing_extensions.TypeAlias = typing.Tuple[
54+
_TPTupleType = typing.Tuple[
5655
asyncio.WriteTransport,
5756
_AsyncProtocolT
5857
]
59-
_SSLStringValues = compat.Literal[
58+
_SSLStringValues = Literal[
6059
'disable', 'prefer', 'allow', 'require', 'verify-ca', 'verify-full'
6160
]
62-
AddrType: typing_extensions.TypeAlias = typing.Union[
61+
AddrType = typing.Union[
6362
typing.Tuple[str, int],
6463
str
6564
]
66-
_ParsedSSLType: typing_extensions.TypeAlias = typing.Union[
67-
ssl_module.SSLContext, compat.Literal[False]
65+
_ParsedSSLType = typing.Union[
66+
ssl_module.SSLContext, Literal[False]
6867
]
69-
SSLType: typing_extensions.TypeAlias = typing.Union[
68+
SSLType = typing.Union[
7069
_ParsedSSLType, _SSLStringValues, bool
7170
]
72-
HostType: typing_extensions.TypeAlias = typing.Union[typing.List[str], str]
73-
PortListType: typing_extensions.TypeAlias = typing.Union[
71+
HostType = typing.Union[typing.List[str], str]
72+
PortListType = typing.Union[
7473
typing.List[typing.Union[int, str]],
7574
typing.List[int],
7675
typing.List[str],
7776
]
78-
PortType: typing_extensions.TypeAlias = typing.Union[
77+
PortType = typing.Union[
7978
PortListType,
8079
int,
8180
str

‎asyncpg/connection.py

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77

88
import asyncio
9-
import typing_extensions
109
import asyncpg
1110
import collections
1211
import collections.abc
@@ -33,40 +32,45 @@
3332
from . import types
3433
from . import utils
3534

35+
# Work around https://github.com/microsoft/pyright/issues/3012
36+
if sys.version_info >= (3, 8):
37+
from typing import Literal
38+
else:
39+
from typing_extensions import Literal
40+
3641
if typing.TYPE_CHECKING:
3742
import io
3843
from .protocol import protocol as _cprotocol
3944
from . import pool_connection_proxy as _pool
4045

41-
4246
_ConnectionT = typing.TypeVar('_ConnectionT', bound='Connection[typing.Any]')
4347
_RecordT = typing.TypeVar('_RecordT', bound=protocol.Record)
4448
_OtherRecordT = typing.TypeVar('_OtherRecordT', bound=protocol.Record)
4549

46-
_Writer: typing_extensions.TypeAlias = typing.Callable[
50+
_Writer = typing.Callable[
4751
[bytes],
4852
typing.Coroutine[typing.Any, typing.Any, None]
4953
]
50-
_RecordsType: typing_extensions.TypeAlias = typing.List[_RecordT]
51-
_RecordsExtraType: typing_extensions.TypeAlias = typing.Tuple[
54+
_RecordsType = typing.List[_RecordT]
55+
_RecordsExtraType = typing.Tuple[
5256
_RecordsType[_RecordT],
5357
bytes,
5458
bool
5559
]
5660

57-
OutputType: typing_extensions.TypeAlias = typing.Union[
61+
OutputType = typing.Union[
5862
'os.PathLike[typing.Any]',
5963
typing.BinaryIO,
6064
_Writer
6165
]
62-
SourceType: typing_extensions.TypeAlias = typing.Union[
66+
SourceType = typing.Union[
6367
'os.PathLike[typing.Any]',
6468
typing.BinaryIO,
6569
typing.AsyncIterable[bytes]
6670
]
6771

68-
CopyFormat = compat.Literal['text', 'csv', 'binary']
69-
PasswordType: typing_extensions.TypeAlias = typing.Union[
72+
CopyFormat = Literal['text', 'csv', 'binary']
73+
PasswordType = typing.Union[
7074
str,
7175
typing.Callable[[], str],
7276
typing.Callable[[], typing.Awaitable[str]]
@@ -2133,7 +2137,7 @@ async def _execute(
21332137
limit: int,
21342138
timeout: typing.Optional[float],
21352139
*,
2136-
return_status: compat.Literal[False] = ...,
2140+
return_status: Literal[False] = ...,
21372141
ignore_custom_codec: bool = ...,
21382142
record_class: None = ...
21392143
) -> _RecordsType[_RecordT]:
@@ -2147,7 +2151,7 @@ async def _execute(
21472151
limit: int,
21482152
timeout: typing.Optional[float],
21492153
*,
2150-
return_status: compat.Literal[False] = ...,
2154+
return_status: Literal[False] = ...,
21512155
ignore_custom_codec: bool = ...,
21522156
record_class: typing.Type[_OtherRecordT]
21532157
) -> _RecordsType[_OtherRecordT]:
@@ -2161,7 +2165,7 @@ async def _execute(
21612165
limit: int,
21622166
timeout: typing.Optional[float],
21632167
*,
2164-
return_status: compat.Literal[False] = ...,
2168+
return_status: Literal[False] = ...,
21652169
ignore_custom_codec: bool = ...,
21662170
record_class: typing.Optional[typing.Type[_OtherRecordT]]
21672171
) -> typing.Union[_RecordsType[_RecordT], _RecordsType[_OtherRecordT]]:
@@ -2175,7 +2179,7 @@ async def _execute(
21752179
limit: int,
21762180
timeout: typing.Optional[float],
21772181
*,
2178-
return_status: compat.Literal[True],
2182+
return_status: Literal[True],
21792183
ignore_custom_codec: bool = ...,
21802184
record_class: None = ...
21812185
) -> _RecordsExtraType[_RecordT]:
@@ -2189,7 +2193,7 @@ async def _execute(
21892193
limit: int,
21902194
timeout: typing.Optional[float],
21912195
*,
2192-
return_status: compat.Literal[True],
2196+
return_status: Literal[True],
21932197
ignore_custom_codec: bool = ...,
21942198
record_class: typing.Type[_OtherRecordT]
21952199
) -> _RecordsExtraType[_OtherRecordT]:
@@ -2226,7 +2230,7 @@ async def __execute(
22262230
limit: int,
22272231
timeout: typing.Optional[float],
22282232
*,
2229-
return_status: compat.Literal[False] = ...,
2233+
return_status: Literal[False] = ...,
22302234
ignore_custom_codec: bool = ...,
22312235
record_class: None = ...
22322236
) -> typing.Tuple[
@@ -2243,7 +2247,7 @@ async def __execute(
22432247
limit: int,
22442248
timeout: typing.Optional[float],
22452249
*,
2246-
return_status: compat.Literal[False] = ...,
2250+
return_status: Literal[False] = ...,
22472251
ignore_custom_codec: bool = ...,
22482252
record_class: typing.Type[_OtherRecordT]
22492253
) -> typing.Tuple[
@@ -2260,7 +2264,7 @@ async def __execute(
22602264
limit: int,
22612265
timeout: typing.Optional[float],
22622266
*,
2263-
return_status: compat.Literal[True],
2267+
return_status: Literal[True],
22642268
ignore_custom_codec: bool = ...,
22652269
record_class: None = ...
22662270
) -> typing.Tuple[
@@ -2277,7 +2281,7 @@ async def __execute(
22772281
limit: int,
22782282
timeout: typing.Optional[float],
22792283
*,
2280-
return_status: compat.Literal[True],
2284+
return_status: Literal[True],
22812285
ignore_custom_codec: bool = ...,
22822286
record_class: typing.Type[_OtherRecordT]
22832287
) -> typing.Tuple[

‎asyncpg/protocol/protocol.pyi

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,15 @@ from typing import (
1919
)
2020

2121
if sys.version_info >= (3, 10):
22-
from typing import Final, TypeAlias, final
22+
from typing import Final, Literal, TypeAlias, final
2323
elif sys.version_info >= (3, 8):
24-
from typing import Final, final
24+
from typing import Final, Literal, final
2525
from typing_extensions import TypeAlias
2626
else:
27-
from typing_extensions import Final, TypeAlias, final
27+
from typing_extensions import Final, Literal, TypeAlias, final
2828

2929
import asyncpg.pgproto.pgproto
3030

31-
from ..compat import Literal
3231
from ..connect_utils import _ConnectionParameters
3332
from ..pgproto.pgproto import WriteBuffer
3433
from ..types import Type, Attribute

‎asyncpg/transaction.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,10 @@
1111

1212
# Work around https://github.com/microsoft/pyright/issues/3012
1313
if sys.version_info >= (3, 8):
14-
from typing import Final
14+
from typing import Final, Literal
1515
else:
16-
from typing_extensions import Final
16+
from typing_extensions import Final, Literal
1717

18-
from . import compat
1918
from . import connresource
2019
from . import exceptions as apg_errors
2120

@@ -32,9 +31,11 @@ class TransactionState(enum.Enum):
3231
FAILED = 4
3332

3433

35-
IsolationLevels = compat.Literal['read_committed',
36-
'serializable',
37-
'repeatable_read']
34+
IsolationLevels = Literal[
35+
'read_committed',
36+
'serializable',
37+
'repeatable_read'
38+
]
3839
ISOLATION_LEVELS: Final[
3940
typing.Set[IsolationLevels]
4041
] = {

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /