Skip to content

Commit c93c1ad

Browse files
committed
Update flake8 (newer pyflakes handles overloads) and update variables
1 parent a484391 commit c93c1ad

File tree

9 files changed

+82
-77
lines changed

9 files changed

+82
-77
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: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,31 +15,32 @@
1515
import typing_extensions
1616

1717

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

2930

3031
if sys.version_info < (3, 5, 2):
31-
def aiter_compat(func: F) -> F_35:
32+
def aiter_compat(func: _F) -> _F_35:
3233
@functools.wraps(func)
3334
async def wrapper(self: typing.Any) -> typing.Any:
3435
return func(self)
35-
return typing.cast(F_35, wrapper)
36+
return typing.cast(_F_35, wrapper)
3637
else:
37-
def aiter_compat(func: F) -> F: # type: ignore
38+
def aiter_compat(func: _F) -> _F: # type: ignore
3839
return func
3940

4041

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

4546

@@ -122,7 +123,7 @@ async def wait_closed(stream: asyncio.StreamWriter) -> None:
122123

123124

124125
# Workaround for https://bugs.python.org/issue37658
125-
async def wait_for(fut: 'asyncio.Future[T]', timeout: float) -> T:
126+
async def wait_for(fut: 'asyncio.Future[_T]', timeout: float) -> _T:
126127
if timeout is None:
127128
return await fut
128129

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:
@@ -718,10 +719,10 @@ async def _connect(
718719
*,
719720
loop: typing.Optional[asyncio.AbstractEventLoop],
720721
timeout: float,
721-
connection_class: typing.Type[C],
722+
connection_class: typing.Type[_Connection],
722723
record_class: typing.Any,
723724
**kwargs: typing.Any
724-
) -> C:
725+
) -> _Connection:
725726
if loop is None:
726727
loop = asyncio.get_event_loop()
727728

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):
@@ -1082,7 +1083,7 @@ async def _copy_out(self, copy_stmt: str,
10821083
# output is not a path-like object
10831084
path = None
10841085

1085-
writer = None # type: typing.Optional[Writer]
1086+
writer = None # type: typing.Optional[_Writer]
10861087
opened_by_us = False
10871088
run_in_executor = self._loop.run_in_executor
10881089

@@ -1658,7 +1659,7 @@ def _set_proxy(self, proxy: typing.Optional['_pool.PoolConnectionProxy']) \
16581659
self._proxy = proxy
16591660

16601661
def _check_listeners(self,
1661-
listeners: 'typing._Collection[AnyCallable]',
1662+
listeners: 'typing._Collection[_AnyCallable]',
16621663
listener_type: str) -> None:
16631664
if listeners:
16641665
count = len(listeners)
@@ -1762,10 +1763,10 @@ async def _execute(
17621763
return_status: typing_extensions.Literal[True],
17631764
ignore_custom_codec: bool = ...,
17641765
record_class: typing.Optional[typing.Any] = ...
1765-
) -> RecordsExtraType:
1766+
) -> _RecordsExtraType:
17661767
...
17671768

1768-
@typing.overload # noqa: F811
1769+
@typing.overload
17691770
async def _execute(
17701771
self,
17711772
query: str,
@@ -1776,10 +1777,10 @@ async def _execute(
17761777
return_status: typing_extensions.Literal[False] = ...,
17771778
ignore_custom_codec: bool = ...,
17781779
record_class: typing.Optional[typing.Any] = ...
1779-
) -> RecordsType:
1780+
) -> _RecordsType:
17801781
...
17811782

1782-
@typing.overload # noqa: F811
1783+
@typing.overload
17831784
async def _execute(
17841785
self,
17851786
query: str,
@@ -1790,13 +1791,13 @@ async def _execute(
17901791
return_status: bool,
17911792
ignore_custom_codec: bool = ...,
17921793
record_class: typing.Optional[typing.Any] = ...
1793-
) -> typing.Union[RecordsExtraType, RecordsType]:
1794+
) -> typing.Union[_RecordsExtraType, _RecordsType]:
17941795
...
17951796

17961797
async def _execute(
17971798
self,
17981799
query: str,
1799-
args: typing.Sequence[typing.Any], # noqa: F811, E501
1800+
args: typing.Sequence[typing.Any],
18001801
limit: int,
18011802
timeout: typing.Optional[float],
18021803
*,
@@ -1827,10 +1828,10 @@ async def __execute(
18271828
return_status: typing_extensions.Literal[True],
18281829
ignore_custom_codec: bool = ...,
18291830
record_class: typing.Optional[typing.Any] = ...
1830-
) -> typing.Tuple[RecordsExtraType, '_cprotocol.PreparedStatementState']:
1831+
) -> typing.Tuple[_RecordsExtraType, '_cprotocol.PreparedStatementState']:
18311832
...
18321833

1833-
@typing.overload # noqa: F811
1834+
@typing.overload
18341835
async def __execute(
18351836
self,
18361837
query: str,
@@ -1841,10 +1842,10 @@ async def __execute(
18411842
return_status: typing_extensions.Literal[False] = ...,
18421843
ignore_custom_codec: bool = ...,
18431844
record_class: typing.Optional[typing.Any] = ...
1844-
) -> typing.Tuple[RecordsType, '_cprotocol.PreparedStatementState']:
1845+
) -> typing.Tuple[_RecordsType, '_cprotocol.PreparedStatementState']:
18451846
...
18461847

1847-
@typing.overload # noqa: F811
1848+
@typing.overload
18481849
async def __execute(
18491850
self,
18501851
query: str,
@@ -1856,21 +1857,21 @@ async def __execute(
18561857
ignore_custom_codec: bool = ...,
18571858
record_class: typing.Optional[typing.Any] = ...
18581859
) -> typing.Union[
1859-
typing.Tuple[RecordsExtraType, '_cprotocol.PreparedStatementState'],
1860-
typing.Tuple[RecordsType, '_cprotocol.PreparedStatementState']
1860+
typing.Tuple[_RecordsExtraType, '_cprotocol.PreparedStatementState'],
1861+
typing.Tuple[_RecordsType, '_cprotocol.PreparedStatementState']
18611862
]:
18621863
...
18631864

18641865
async def __execute(
18651866
self,
1866-
query: str, # noqa: F811
1867+
query: str,
18671868
args: typing.Sequence[typing.Any],
18681869
limit: int,
18691870
timeout: typing.Optional[float],
18701871
*,
18711872
return_status: bool = False,
18721873
ignore_custom_codec: bool = False,
1873-
record_class: typing.Optional[typing.Any] = ...
1874+
record_class: typing.Optional[typing.Any] = None
18741875
) -> typing.Tuple[typing.Any, '_cprotocol.PreparedStatementState']:
18751876
executor = lambda stmt, timeout: self._protocol.bind_execute(
18761877
stmt, args, '', limit, return_status, timeout)
@@ -1995,7 +1996,7 @@ async def connect(dsn: typing.Optional[str] = ..., *,
19951996
...
19961997

19971998

1998-
@typing.overload # noqa: F811
1999+
@typing.overload
19992000
async def connect(dsn: typing.Optional[str] = ..., *,
20002001
host: typing.Optional[connect_utils.HostType] = ...,
20012002
port: typing.Optional[connect_utils.PortType] = ...,
@@ -2010,14 +2011,14 @@ async def connect(dsn: typing.Optional[str] = ..., *,
20102011
max_cacheable_statement_size: int = ...,
20112012
command_timeout: typing.Optional[float] = ...,
20122013
ssl: typing.Optional[connect_utils.SSLType] = ...,
2013-
connection_class: typing.Type[C],
2014+
connection_class: typing.Type[_Connection],
20142015
record_class: typing.Optional[typing.Any] = ...,
20152016
server_settings: typing.Optional[
2016-
typing.Dict[str, str]] = ...) -> C:
2017+
typing.Dict[str, str]] = ...) -> _Connection:
20172018
...
20182019

20192020

2020-
async def connect(dsn: typing.Optional[str] = None, *, # noqa: F811
2021+
async def connect(dsn: typing.Optional[str] = None, *,
20212022
host: typing.Optional[connect_utils.HostType] = None,
20222023
port: typing.Optional[connect_utils.PortType] = None,
20232024
user: typing.Optional[str] = None,
@@ -2031,11 +2032,10 @@ async def connect(dsn: typing.Optional[str] = None, *, # noqa: F811
20312032
max_cacheable_statement_size: int = 1024 * 15,
20322033
command_timeout: typing.Optional[float] = None,
20332034
ssl: typing.Optional[connect_utils.SSLType] = None,
2034-
connection_class: typing.Type[C] = \
2035-
Connection, # type: ignore
2035+
connection_class: typing.Type[_Connection] = Connection, # type: ignore # noqa: E501
20362036
record_class: typing.Optional[typing.Any] = protocol.Record,
20372037
server_settings: typing.Optional[
2038-
typing.Dict[str, str]] = None) -> C:
2038+
typing.Dict[str, str]] = None) -> _Connection:
20392039
r"""A coroutine to establish a connection to a PostgreSQL server.
20402040
20412041
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)