Skip to content

Commit 93fcf40

Browse files
committed
Update flake8 (newer pyflakes handles overloads) and update variables
1 parent 0ab978d commit 93fcf40

File tree

10 files changed

+83
-76
lines changed

10 files changed

+83
-76
lines changed

.flake8

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
[flake8]
22
ignore = E402,E731,W503,W504,E252
3-
exclude = .git,__pycache__,build,dist,.eggs,.github,.local
3+
exclude = .git,__pycache__,build,dist,.eggs,.github,.local,.venv*
44
per-file-ignores = *.pyi: F401, F403, F405, F811, E127, E128, E203, E266, E301, E302, E305, E501, E701, E704, E741, B303, W503, W504

asyncpg/compat.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,30 +15,31 @@
1515
import typing_extensions
1616

1717

18-
T_co = typing.TypeVar('T_co', covariant=True)
19-
F = typing.TypeVar('F', bound=typing.Callable[..., typing.Any])
20-
F_35 = typing.TypeVar('F_35', bound=typing.Callable[
18+
_T_co = typing.TypeVar('_T_co', covariant=True)
19+
_F = typing.TypeVar('_F', bound=typing.Callable[..., typing.Any])
20+
_F_35 = typing.TypeVar('_F_35', bound=typing.Callable[
2121
...,
2222
typing.Coroutine[typing.Any, typing.Any, typing.Any]
2323
])
24+
2425
PY_36 = sys.version_info >= (3, 6)
2526
PY_37 = sys.version_info >= (3, 7)
2627
SYSTEM = platform.uname().system
2728

2829

2930
if sys.version_info < (3, 5, 2):
30-
def aiter_compat(func: F) -> F_35:
31+
def aiter_compat(func: _F) -> _F_35:
3132
@functools.wraps(func)
3233
async def wrapper(self: typing.Any) -> typing.Any:
3334
return func(self)
34-
return typing.cast(F_35, wrapper)
35+
return typing.cast(_F_35, wrapper)
3536
else:
36-
def aiter_compat(func: F) -> F: # type: ignore
37+
def aiter_compat(func: _F) -> _F: # type: ignore
3738
return func
3839

3940

40-
class PathLike(typing_extensions.Protocol[T_co]):
41-
def __fspath__(self) -> T_co:
41+
class PathLike(typing_extensions.Protocol[_T_co]):
42+
def __fspath__(self) -> _T_co:
4243
...
4344

4445

asyncpg/connect_utils.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@
2727
from . import exceptions
2828
from . import protocol
2929

30-
C = typing.TypeVar('C')
31-
P = typing.TypeVar('P', bound=asyncio.Protocol)
30+
_Connection = typing.TypeVar('_Connection')
31+
_Protocol = typing.TypeVar('_Protocol', bound=asyncio.Protocol)
3232

33-
_TPTupleType = typing.Tuple[asyncio.WriteTransport, P]
33+
_TPTupleType = typing.Tuple[asyncio.WriteTransport, _Protocol]
3434
AddrType = typing.Union[typing.Tuple[str, int], str]
3535
SSLType = typing.Union[ssl_module.SSLContext,
3636
typing_extensions.Literal[True]]
@@ -577,14 +577,15 @@ def connection_lost(self, exc: typing.Optional[Exception]) -> None:
577577
self.on_data.set_exception(exc)
578578

579579

580-
async def _create_ssl_connection(protocol_factory: typing.Callable[[], P],
580+
async def _create_ssl_connection(protocol_factory: typing.Callable[[],
581+
_Protocol],
581582
host: str, port: int, *,
582583
loop: asyncio.AbstractEventLoop,
583584
ssl_context: typing.Union[
584585
ssl_module.SSLContext,
585586
typing_extensions.Literal[True]],
586587
ssl_is_advisory: typing.Optional[bool] =
587-
False) -> _TPTupleType[P]:
588+
False) -> _TPTupleType[_Protocol]:
588589

589590
if ssl_context is True:
590591
ssl_context = ssl_module.create_default_context()
@@ -641,7 +642,7 @@ async def _create_ssl_connection(protocol_factory: typing.Callable[[], P],
641642

642643
try:
643644
return typing.cast(
644-
typing.Tuple[asyncio.WriteTransport, P],
645+
typing.Tuple[asyncio.WriteTransport, _Protocol],
645646
await conn_factory(sock=sock)
646647
)
647648
except (Exception, asyncio.CancelledError):
@@ -656,9 +657,9 @@ async def _connect_addr(
656657
timeout: float,
657658
params: _ConnectionParameters,
658659
config: _ClientConfiguration,
659-
connection_class: typing.Type[C],
660+
connection_class: typing.Type[_Connection],
660661
record_class: typing.Any
661-
) -> C:
662+
) -> _Connection:
662663
assert loop is not None
663664

664665
if timeout <= 0:
@@ -723,10 +724,10 @@ async def _connect(
723724
*,
724725
loop: typing.Optional[asyncio.AbstractEventLoop],
725726
timeout: float,
726-
connection_class: typing.Type[C],
727+
connection_class: typing.Type[_Connection],
727728
record_class: typing.Any,
728729
**kwargs: typing.Any
729-
) -> C:
730+
) -> _Connection:
730731
if loop is None:
731732
loop = asyncio.get_event_loop()
732733

asyncpg/connection.py

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -35,23 +35,24 @@
3535
from . import types
3636

3737

38-
C = typing.TypeVar('C', bound='Connection')
39-
Writer = typing.Callable[[bytes],
40-
typing.Coroutine[typing.Any, typing.Any, None]]
38+
_Connection = typing.TypeVar('_Connection', bound='Connection')
39+
_Writer = typing.Callable[[bytes],
40+
typing.Coroutine[typing.Any, typing.Any, None]]
41+
_RecordsType = typing.List['_cprotocol.Record']
42+
_RecordsExtraType = typing.Tuple[_RecordsType, bytes, bool]
43+
_AnyCallable = typing.Callable[..., typing.Any]
44+
4145
OutputType = typing.Union[typing.AnyStr,
4246
compat.PathLike[typing.AnyStr],
4347
typing.IO[typing.AnyStr],
44-
Writer]
48+
_Writer]
4549
SourceType = typing.Union[typing.AnyStr,
4650
compat.PathLike[typing.AnyStr],
4751
typing.IO[typing.AnyStr],
4852
typing.AsyncIterable[bytes]]
4953

5054
CopyFormat = typing_extensions.Literal['text', 'csv', 'binary']
5155
PasswordType = typing.Union[str, typing.Callable[[], str]]
52-
RecordsType = typing.List['_cprotocol.Record']
53-
RecordsExtraType = typing.Tuple[RecordsType, bytes, bool]
54-
AnyCallable = typing.Callable[..., typing.Any]
5556

5657

5758
class Listener(typing_extensions.Protocol):
@@ -1042,7 +1043,7 @@ async def _copy_out(self, copy_stmt: str,
10421043
# output is not a path-like object
10431044
path = None
10441045

1045-
writer = None # type: typing.Optional[Writer]
1046+
writer = None # type: typing.Optional[_Writer]
10461047
opened_by_us = False
10471048
run_in_executor = self._loop.run_in_executor
10481049

@@ -1633,7 +1634,7 @@ def _set_proxy(self, proxy: typing.Optional['_pool.PoolConnectionProxy']) \
16331634
self._proxy = proxy
16341635

16351636
def _check_listeners(self,
1636-
listeners: 'typing._Collection[AnyCallable]',
1637+
listeners: 'typing._Collection[_AnyCallable]',
16371638
listener_type: str) -> None:
16381639
if listeners:
16391640
count = len(listeners)
@@ -1736,10 +1737,10 @@ async def _execute(
17361737
*,
17371738
return_status: typing_extensions.Literal[True],
17381739
record_class: typing.Optional[typing.Any] = ...
1739-
) -> RecordsExtraType:
1740+
) -> _RecordsExtraType:
17401741
...
17411742

1742-
@typing.overload # noqa: F811
1743+
@typing.overload
17431744
async def _execute(
17441745
self,
17451746
query: str,
@@ -1749,10 +1750,10 @@ async def _execute(
17491750
*,
17501751
return_status: typing_extensions.Literal[False] = ...,
17511752
record_class: typing.Optional[typing.Any] = ...
1752-
) -> RecordsType:
1753+
) -> _RecordsType:
17531754
...
17541755

1755-
@typing.overload # noqa: F811
1756+
@typing.overload
17561757
async def _execute(
17571758
self,
17581759
query: str,
@@ -1762,13 +1763,13 @@ async def _execute(
17621763
*,
17631764
return_status: bool,
17641765
record_class: typing.Optional[typing.Any] = ...
1765-
) -> typing.Union[RecordsExtraType, RecordsType]:
1766+
) -> typing.Union[_RecordsExtraType, _RecordsType]:
17661767
...
17671768

17681769
async def _execute(
17691770
self,
17701771
query: str,
1771-
args: typing.Sequence[typing.Any], # noqa: F811, E501
1772+
args: typing.Sequence[typing.Any],
17721773
limit: int,
17731774
timeout: typing.Optional[float],
17741775
*,
@@ -1796,10 +1797,10 @@ async def __execute(
17961797
*,
17971798
return_status: typing_extensions.Literal[True],
17981799
record_class: typing.Optional[typing.Any] = ...
1799-
) -> typing.Tuple[RecordsExtraType, '_cprotocol.PreparedStatementState']:
1800+
) -> typing.Tuple[_RecordsExtraType, '_cprotocol.PreparedStatementState']:
18001801
...
18011802

1802-
@typing.overload # noqa: F811
1803+
@typing.overload
18031804
async def __execute(
18041805
self,
18051806
query: str,
@@ -1809,10 +1810,10 @@ async def __execute(
18091810
*,
18101811
return_status: typing_extensions.Literal[False] = ...,
18111812
record_class: typing.Optional[typing.Any] = ...
1812-
) -> typing.Tuple[RecordsType, '_cprotocol.PreparedStatementState']:
1813+
) -> typing.Tuple[_RecordsType, '_cprotocol.PreparedStatementState']:
18131814
...
18141815

1815-
@typing.overload # noqa: F811
1816+
@typing.overload
18161817
async def __execute(
18171818
self,
18181819
query: str,
@@ -1823,20 +1824,20 @@ async def __execute(
18231824
return_status: bool,
18241825
record_class: typing.Optional[typing.Any] = ...
18251826
) -> typing.Union[
1826-
typing.Tuple[RecordsExtraType, '_cprotocol.PreparedStatementState'],
1827-
typing.Tuple[RecordsType, '_cprotocol.PreparedStatementState']
1827+
typing.Tuple[_RecordsExtraType, '_cprotocol.PreparedStatementState'],
1828+
typing.Tuple[_RecordsType, '_cprotocol.PreparedStatementState']
18281829
]:
18291830
...
18301831

18311832
async def __execute(
18321833
self,
1833-
query: str, # noqa: F811
1834+
query: str,
18341835
args: typing.Sequence[typing.Any],
18351836
limit: int,
18361837
timeout: typing.Optional[float],
18371838
*,
18381839
return_status: bool = False,
1839-
record_class: typing.Optional[typing.Any] = ...
1840+
record_class: typing.Optional[typing.Any] = None
18401841
) -> typing.Tuple[typing.Any, '_cprotocol.PreparedStatementState']:
18411842
executor = lambda stmt, timeout: self._protocol.bind_execute(
18421843
stmt, args, '', limit, return_status, timeout)
@@ -1957,7 +1958,7 @@ async def connect(dsn: typing.Optional[str] = ..., *,
19571958
...
19581959

19591960

1960-
@typing.overload # noqa: F811
1961+
@typing.overload
19611962
async def connect(dsn: typing.Optional[str] = ..., *,
19621963
host: typing.Optional[connect_utils.HostType] = ...,
19631964
port: typing.Optional[connect_utils.PortType] = ...,
@@ -1972,14 +1973,14 @@ async def connect(dsn: typing.Optional[str] = ..., *,
19721973
max_cacheable_statement_size: int = ...,
19731974
command_timeout: typing.Optional[float] = ...,
19741975
ssl: typing.Optional[connect_utils.SSLType] = ...,
1975-
connection_class: typing.Type[C],
1976+
connection_class: typing.Type[_Connection],
19761977
record_class: typing.Optional[typing.Any] = ...,
19771978
server_settings: typing.Optional[
1978-
typing.Dict[str, str]] = ...) -> C:
1979+
typing.Dict[str, str]] = ...) -> _Connection:
19791980
...
19801981

19811982

1982-
async def connect(dsn: typing.Optional[str] = None, *, # noqa: F811
1983+
async def connect(dsn: typing.Optional[str] = None, *,
19831984
host: typing.Optional[connect_utils.HostType] = None,
19841985
port: typing.Optional[connect_utils.PortType] = None,
19851986
user: typing.Optional[str] = None,
@@ -1993,11 +1994,10 @@ async def connect(dsn: typing.Optional[str] = None, *, # noqa: F811
19931994
max_cacheable_statement_size: int = 1024 * 15,
19941995
command_timeout: typing.Optional[float] = None,
19951996
ssl: typing.Optional[connect_utils.SSLType] = None,
1996-
connection_class: typing.Type[C] = \
1997-
Connection, # type: ignore
1997+
connection_class: typing.Type[_Connection] = Connection, # type: ignore # noqa: E501
19981998
record_class: typing.Optional[typing.Any] = protocol.Record,
19991999
server_settings: typing.Optional[
2000-
typing.Dict[str, str]] = None) -> C:
2000+
typing.Dict[str, str]] = None) -> _Connection:
20012001
r"""A coroutine to establish a connection to a PostgreSQL server.
20022002
20032003
The connection parameters may be specified either as a connection

asyncpg/connresource.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,22 @@
1616
from . import connection as _connection
1717

1818

19-
CR = typing.TypeVar('CR', bound='ConnectionResource')
20-
F = typing.TypeVar('F', bound=typing.Callable[..., typing.Any])
19+
_ConnectionResource = typing.TypeVar('_ConnectionResource',
20+
bound='ConnectionResource')
21+
_Callable = typing.TypeVar('_Callable', bound=typing.Callable[..., typing.Any])
2122

2223

23-
def guarded(meth: F) -> F:
24+
def guarded(meth: _Callable) -> _Callable:
2425
"""A decorator to add a sanity check to ConnectionResource methods."""
2526

2627
@functools.wraps(meth)
27-
def _check(self: CR,
28+
def _check(self: _ConnectionResource,
2829
*args: typing.Any,
2930
**kwargs: typing.Any) -> typing.Any:
3031
self._check_conn_validity(meth.__name__)
3132
return meth(self, *args, **kwargs)
3233

33-
return typing.cast(F, _check)
34+
return typing.cast(_Callable, _check)
3435

3536

3637
class ConnectionResource:

0 commit comments

Comments
 (0)