Skip to content

Commit da85005

Browse files
committed
Update to 3.6 type annotations and remove 3.5 compatibility
1 parent b9e0ef9 commit da85005

File tree

14 files changed

+112
-191
lines changed

14 files changed

+112
-191
lines changed

‎.travis.yml‎

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ language: generic
33
env:
44
global:
55
- PYMODULE=asyncpg
6-
- RELEASE_PYTHON_VERSIONS="3.5 3.6 3.7 3.8"
6+
- RELEASE_PYTHON_VERSIONS="3.6 3.7 3.8"
77

88
- S3_UPLOAD_USERNAME=oss-ci-bot
99
- S3_UPLOAD_BUCKET=magicstack-oss-releases
@@ -93,20 +93,6 @@ jobs:
9393

9494
# Do a full test run on the latest supported version of PostgreSQL
9595
# on each supported version of Python.
96-
- name: "Test py 3.5"
97-
os: linux
98-
dist: focal
99-
language: python
100-
python: "3.5"
101-
env: BUILD=tests PGVERSION=12
102-
addons:
103-
apt:
104-
sources:
105-
- sourceline: 'deb https://apt.postgresql.org/pub/repos/apt/ focal-pgdg main'
106-
key_url: 'https://www.postgresql.org/media/keys/ACCC4CF8.asc'
107-
packages:
108-
- postgresql-12
109-
11096
- name: "Test py 3.6"
11197
os: linux
11298
dist: focal
@@ -195,10 +181,6 @@ jobs:
195181
addons:
196182
postgresql: "12"
197183

198-
- name: "OSX py 3.5"
199-
os: osx
200-
env: BUILD=tests,wheels PYTHON_VERSION=3.5.9 PGVERSION=12
201-
202184
- name: "OSX py 3.6"
203185
os: osx
204186
env: BUILD=tests,wheels PYTHON_VERSION=3.6.10 PGVERSION=12

‎asyncpg/cluster.py‎

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,9 @@
3131
from . importtypes
3232

3333

34-
_ConnectionSpec=typing_extensions.TypedDict('_ConnectionSpec',{
35-
'host': str,
36-
'port': str
37-
})
34+
class_ConnectionSpec(typing_extensions.TypedDict):
35+
host: str
36+
port: str
3837

3938

4039
_system=platform.uname().system
@@ -53,7 +52,7 @@ def find_available_port(port_range: typing.Tuple[int, int] = (49152, 65535),
5352
max_tries: int=1000) ->typing.Optional[int]:
5453
low, high=port_range
5554

56-
port=low# type: typing.Optional[int]
55+
port: typing.Optional[int]=low
5756
try_no=0
5857

5958
whiletry_no<max_tries:
@@ -85,11 +84,11 @@ def __init__(self, data_dir: str, *,
8584
self._data_dir=data_dir
8685
self._pg_config_path=pg_config_path
8786
self._pg_bin_dir=os.environ.get('PGINSTALLATION')
88-
self._pg_ctl=None# type: typing.Optional[str]
89-
self._daemon_pid=None# type: typing.Optional[int]
90-
self._daemon_process=None# type: typing.Optional[subprocess.Popen[bytes]] # noqa: E501
91-
self._connection_addr=None# type: typing.Optional[_ConnectionSpec]
92-
self._connection_spec_override=None# type: typing.Optional[_ConnectionSpec] # noqa: E501
87+
self._pg_ctl: typing.Optional[str]=None
88+
self._daemon_pid: typing.Optional[int]=None
89+
self._daemon_process: typing.Optional[subprocess.Popen[bytes]] =None
90+
self._connection_addr: typing.Optional[_ConnectionSpec]=None
91+
self._connection_spec_override: typing.Optional[_ConnectionSpec] =None
9392

9493
defget_pg_version(self) ->'types.ServerVersion':
9594
returnself._pg_version
@@ -132,7 +131,7 @@ def get_status(self) -> str:
132131
asyncdefconnect(self,
133132
loop: typing.Optional[asyncio.AbstractEventLoop] =None,
134133
**kwargs: typing.Any) ->'connection.Connection':
135-
conn_info=self.get_connection_spec() # type: typing.Optional[typing.Any] # noqa: E501
134+
conn_info: typing.Optional[typing.Any] =self.get_connection_spec()
136135
conn_info.update(kwargs) # type: ignore[union-attr]
137136
returnawaitasyncpg.connect(loop=loop, **conn_info) # type: ignore[misc] # noqa: E501
138137

@@ -215,7 +214,7 @@ def start(self, wait: int = 60, *,
215214
# is not permitted and there is no easy way to drop
216215
# privileges.
217216
ifos.getenv('ASYNCPG_DEBUG_SERVER'):
218-
stdout=sys.stdout# type: typing.Union[int, typing.TextIO]
217+
stdout: typing.Union[int, typing.TextIO]=sys.stdout
219218
else:
220219
stdout=subprocess.DEVNULL
221220

‎asyncpg/compat.py‎

Lines changed: 0 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -6,78 +6,17 @@
66

77

88
importasyncio
9-
importfunctools
10-
importos
119
importpathlib
1210
importplatform
1311
importsys
1412
importtyping
15-
importtyping_extensions
1613

1714

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[
21-
...,
22-
typing.Coroutine[typing.Any, typing.Any, typing.Any]
23-
])
24-
2515
PY_36=sys.version_info>= (3, 6)
2616
PY_37=sys.version_info>= (3, 7)
2717
SYSTEM=platform.uname().system
2818

2919

30-
ifsys.version_info< (3, 5, 2):
31-
defaiter_compat(func: _F) ->_F_35:
32-
@functools.wraps(func)
33-
asyncdefwrapper(self: typing.Any) ->typing.Any:
34-
returnfunc(self)
35-
returntyping.cast(_F_35, wrapper)
36-
else:
37-
defaiter_compat(func: _F) ->_F: # type: ignore[misc]
38-
returnfunc
39-
40-
41-
classPathLike(typing_extensions.Protocol[_T_co]):
42-
def__fspath__(self) ->_T_co:
43-
...
44-
45-
46-
ifsys.version_info>= (3, 6):
47-
fspath=os.fspath
48-
else:
49-
@typing.overload
50-
deffspath(path: str) ->str:
51-
...
52-
53-
@typing.overload
54-
deffspath(path: bytes) ->bytes:
55-
...
56-
57-
@typing.overload
58-
deffspath(path: PathLike[typing.AnyStr]) ->typing.AnyStr:
59-
...
60-
61-
deffspath(path: typing.Any) ->typing.Any:
62-
fsp=getattr(path, '__fspath__', None)
63-
iffspisnotNoneandcallable(fsp):
64-
path=fsp()
65-
ifnotisinstance(path, (str, bytes)):
66-
raiseTypeError(
67-
'expected{}() to return str or bytes, not{}'.format(
68-
fsp.__qualname__, type(path).__name__
69-
))
70-
returnpath
71-
elifisinstance(path, (str, bytes)):
72-
returnpath
73-
else:
74-
raiseTypeError(
75-
'expected str, bytes or path-like object, not{}'.format(
76-
type(path).__name__
77-
)
78-
)
79-
80-
8120
ifSYSTEM=='Windows':
8221
importctypes.wintypes
8322

‎asyncpg/connect_utils.py‎

Lines changed: 24 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -37,27 +37,22 @@
3737
HostType=typing.Union[typing.List[str], str]
3838
PortType=typing.Union[typing.List[int], int]
3939

40-
_ConnectionParameters=typing.NamedTuple(
41-
'ConnectionParameters',
42-
[
43-
('user', str),
44-
('password', typing.Optional[str]),
45-
('database', str),
46-
('ssl', typing.Optional[SSLType]),
47-
('ssl_is_advisory', typing.Optional[bool]),
48-
('connect_timeout', typing.Optional[float]),
49-
('server_settings', typing.Optional[typing.Dict[str, str]])
50-
])
51-
52-
53-
_ClientConfiguration=typing.NamedTuple(
54-
'ConnectionConfiguration',
55-
[
56-
('command_timeout', typing.Optional[float]),
57-
('statement_cache_size', int),
58-
('max_cached_statement_lifetime', int),
59-
('max_cacheable_statement_size', int),
60-
])
40+
41+
class_ConnectionParameters(typing.NamedTuple):
42+
user: str
43+
password: typing.Optional[str]
44+
database: str
45+
ssl: typing.Optional[SSLType]
46+
ssl_is_advisory: typing.Optional[bool]
47+
connect_timeout: typing.Optional[float]
48+
server_settings: typing.Optional[typing.Dict[str, str]]
49+
50+
51+
class_ClientConfiguration(typing.NamedTuple):
52+
command_timeout: typing.Optional[float]
53+
statement_cache_size: int
54+
max_cached_statement_lifetime: int
55+
max_cacheable_statement_size: int
6156

6257

6358
_system=platform.uname().system
@@ -175,15 +170,16 @@ def _parse_hostlist(hostlist: str,
175170
else:
176171
hostspecs= [hostlist]
177172

178-
hosts= [] # type: typing.List[str]
179-
hostlist_ports= [] # type: typing.List[int]
180-
ports=None# type: typing.Optional[typing.List[int]]
173+
hosts: typing.List[str] = []
174+
hostlist_ports: typing.List[int] = []
175+
ports: typing.Optional[typing.List[int]]=None
181176

182177
ifnotport:
183178
portspec=os.environ.get('PGPORT')
184179
ifportspec:
185180
if','inportspec:
186-
temp_port= [int(p) forpinportspec.split(',')] # type: typing.Union[typing.List[int], int] # noqa: E501
181+
temp_port: typing.Union[typing.List[int], int] = [
182+
int(p) forpinportspec.split(',')]
187183
else:
188184
temp_port=int(portspec)
189185
else:
@@ -274,7 +270,7 @@ def _parse_connect_dsn_and_args(*, dsn: typing.Optional[str],
274270

275271
ifparsed.query:
276272
query=urllib.parse.parse_qs(parsed.query, strict_parsing=True)
277-
query_str={} # type: typing.Dict[str, str]
273+
query_str: typing.Dict[str, str]={}
278274
forkey, valinquery.items():
279275
ifisinstance(val, list):
280276
query_str[key] =val[-1]
@@ -404,7 +400,7 @@ def _parse_connect_dsn_and_args(*, dsn: typing.Optional[str],
404400
database=database, user=user,
405401
passfile=passfile) # type: ignore[arg-type]
406402

407-
addrs= [] # type: typing.List[AddrType]
403+
addrs: typing.List[AddrType] = []
408404
forh, pinzip(host, port):
409405
ifh.startswith('/'):
410406
# UNIX socket name
@@ -726,7 +722,7 @@ async def _connect(*, loop: typing.Optional[asyncio.AbstractEventLoop],
726722

727723
addrs, params, config=_parse_connect_arguments(timeout=timeout, **kwargs)
728724

729-
last_error=None# type: typing.Optional[BaseException]
725+
last_error: typing.Optional[BaseException]=None
730726
addr=None
731727
foraddrinaddrs:
732728
before=time.monotonic()

0 commit comments

Comments
(0)