Skip to content

Commit 6928201

Browse files
committed
Rewrite async_timeout
1 parent 369aea6 commit 6928201

File tree

3 files changed

+42
-0
lines changed

3 files changed

+42
-0
lines changed

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,11 @@ some examples:
310310
+from typing import Concatenate
311311
```
312312

313+
```diff
314+
-from async_timeout import timeout, timeout_at
315+
+from asyncio import timeout, timeout_at
316+
```
317+
313318
### rewrite `mock` imports
314319

315320
Availability:

pyupgrade/_plugins/imports.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,8 @@
196196
('typing_extensions', 'is_typeddict'): 'typing',
197197
},
198198
(3, 11): {
199+
('async_timeout', 'timeout'): 'asyncio',
200+
('async_timeout', 'timeout_at'): 'asyncio',
199201
('typing_extensions', 'Any'): 'typing',
200202
('typing_extensions', 'LiteralString'): 'typing',
201203
('typing_extensions', 'Never'): 'typing',

tests/features/import_replaces_test.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@
3030
(3,),
3131
id='inline import-import',
3232
),
33+
pytest.param(
34+
'if True: from async_timeout import timeout, other_name\n',
35+
(3, 11),
36+
id='inline async_timeout mixed imports',
37+
),
3338
pytest.param(
3439
'import xml.etree.cElementTree',
3540
(3,),
@@ -45,6 +50,11 @@
4550
(3, 9),
4651
id='skip rewriting of Callable in 3.9 since it is broken',
4752
),
53+
pytest.param(
54+
'from async_timeout import timeout, timeout_at\n',
55+
(3, 10),
56+
id='async_timeout timeout imports below 3.11',
57+
),
4858
),
4959
)
5060
def test_import_replaces_noop(s, min_version):
@@ -77,6 +87,24 @@ def test_mock_noop_keep_mock():
7787
'from collections.abc import Mapping as MAP\n',
7888
id='one-name replacement with alias',
7989
),
90+
pytest.param(
91+
'from async_timeout import timeout\n',
92+
(3, 11),
93+
'from asyncio import timeout\n',
94+
id='async_timeout timeout',
95+
),
96+
pytest.param(
97+
'from async_timeout import timeout as t\n',
98+
(3, 11),
99+
'from asyncio import timeout as t\n',
100+
id='async_timeout timeout alias',
101+
),
102+
pytest.param(
103+
'from async_timeout import timeout, timeout_at\n',
104+
(3, 11),
105+
'from asyncio import timeout, timeout_at\n',
106+
id='async_timeout timeout names',
107+
),
80108
pytest.param(
81109
'from collections import Mapping, Sequence\n',
82110
(3,),
@@ -90,6 +118,13 @@ def test_mock_noop_keep_mock():
90118
'from collections.abc import Mapping\n',
91119
id='one name rewritten to new module',
92120
),
121+
pytest.param(
122+
'from async_timeout import timeout, other_name\n',
123+
(3, 11),
124+
'from async_timeout import other_name\n'
125+
'from asyncio import timeout\n',
126+
id='async_timeout mixed imports',
127+
),
93128
pytest.param(
94129
'from collections import Counter, Mapping',
95130
(3,),

0 commit comments

Comments
 (0)