File tree 7 files changed +41
-24
lines changed 7 files changed +41
-24
lines changed Original file line number Diff line number Diff line change @@ -4,20 +4,24 @@ Changelog
4
4
5
5
`CalVer, YY.month.patch <https://calver.org/ >`_
6
6
7
+ 24.11.2
8
+ =======
9
+ - Fix crash in ``Visitor91x `` on ``async with a().b(): ``.
10
+
7
11
24.11.1
8
12
=======
9
13
- :ref: `ASYNC100 <async100 >` now ignores :func: `trio.open_nursery ` and :func: `anyio.create_task_group `
10
14
as cancellation sources, because they are :ref: `schedule points <schedule_points >` but not
11
15
:ref: `cancellation points <cancel_points >`.
16
+ - :ref: `ASYNC101 <async101 >` and :ref: `ASYNC119 <async119 >` are now silenced for decorators in :ref: `transform-async-generator-decorators `.
12
17
13
18
24.10.2
14
19
=======
15
- - :ref: `ASYNC101 <async101 >` and :ref: `ASYNC119 <async119 >` are now silenced for decorators in :ref: `transform-async-generator-decorators `
16
20
- :ref: `ASYNC102 <async102 >` now also warns about ``await() `` inside ``__aexit__ ``.
17
21
18
22
24.10.1
19
23
=======
20
- - Add :ref: `ASYNC123 <async123 >` bad-exception-group-flattening
24
+ - Add :ref: `ASYNC123 <async123 >` bad-exception-group-flattening.
21
25
22
26
24.9.5
23
27
======
Original file line number Diff line number Diff line change 38
38
39
39
40
40
# CalVer: YY.month.patch, e.g. first release of July 2022 == "22.7.1"
41
- __version__ = "24.11.1 "
41
+ __version__ = "24.11.2 "
42
42
43
43
44
44
# taken from https://github.com/Zac-HD/shed
Original file line number Diff line number Diff line change @@ -337,15 +337,20 @@ def build_cst_matcher(attr: str) -> m.BaseExpression:
337
337
return m .Attribute (value = build_cst_matcher (body ), attr = m .Name (value = tail ))
338
338
339
339
340
- def identifier_to_string (attr : cst .Name | cst .Attribute ) -> str | None :
341
- if isinstance (attr , cst .Name ):
342
- return attr .value
343
- if not isinstance (attr .value , (cst .Attribute , cst .Name )):
344
- return None
345
- lhs = identifier_to_string (attr .value )
346
- if lhs is None :
347
- return None
348
- return lhs + "." + attr .attr .value
340
+ def identifier_to_string (node : cst .CSTNode ) -> str | None :
341
+ """Convert a simple identifier to a string.
342
+
343
+ If the node is composed of anything but cst.Name + cst.Attribute it returns None.
344
+ """
345
+ if isinstance (node , cst .Name ):
346
+ return node .value
347
+ if (
348
+ isinstance (node , cst .Attribute )
349
+ and (lhs := identifier_to_string (node .value )) is not None
350
+ ):
351
+ return lhs + "." + node .attr .value
352
+
353
+ return None
349
354
350
355
351
356
def with_has_call (
Original file line number Diff line number Diff line change @@ -501,17 +501,16 @@ def _checkpoint_with(self, node: cst.With):
501
501
"""
502
502
if getattr (node , "asynchronous" , None ):
503
503
for item in node .items :
504
- if not isinstance (item .item , cst .Call ) or not isinstance (
505
- item .item .func , (cst .Attribute , cst .Name )
504
+ if not (
505
+ isinstance (item .item , cst .Call )
506
+ and identifier_to_string (item .item .func )
507
+ in (
508
+ "trio.open_nursery" ,
509
+ "anyio.create_task_group" ,
510
+ )
506
511
):
507
512
self .checkpoint ()
508
513
break
509
-
510
- func = identifier_to_string (item .item .func )
511
- assert func is not None
512
- if func not in ("trio.open_nursery" , "anyio.create_task_group" ):
513
- self .checkpoint ()
514
- break
515
514
else :
516
515
self .uncheckpointed_statements = set ()
517
516
Original file line number Diff line number Diff line change 5
5
import ast
6
6
from typing import TYPE_CHECKING , Any , cast
7
7
8
- import libcst as cst
9
-
10
8
from .flake8asyncvisitor import Flake8AsyncVisitor , Flake8AsyncVisitor_cst
11
9
from .helpers import (
12
10
disabled_by_default ,
20
18
if TYPE_CHECKING :
21
19
from collections .abc import Mapping
22
20
21
+ import libcst as cst
22
+
23
23
LIBRARIES = ("trio" , "anyio" , "asyncio" )
24
24
25
25
@@ -460,8 +460,7 @@ def visit_CompIf(self, node: cst.CSTNode):
460
460
461
461
def visit_Call (self , node : cst .Call ):
462
462
if (
463
- isinstance (node .func , (cst .Name , cst .Attribute ))
464
- and identifier_to_string (node .func ) == "asyncio.create_task"
463
+ identifier_to_string (node .func ) == "asyncio.create_task"
465
464
and not self .safe_to_create_task
466
465
):
467
466
self .error (node )
Original file line number Diff line number Diff line change @@ -141,3 +141,8 @@ async def nursery_no_cancel_point():
141
141
async def dont_crash_on_non_name_or_attr_call ():
142
142
async with contextlib .asynccontextmanager (agen_fn )():
143
143
...
144
+
145
+
146
+ async def another_weird_with_call ():
147
+ async with a ().b ():
148
+ ...
Original file line number Diff line number Diff line change @@ -141,3 +141,8 @@ async def nursery_no_cancel_point():
141
141
async def dont_crash_on_non_name_or_attr_call ():
142
142
async with contextlib .asynccontextmanager (agen_fn )():
143
143
...
144
+
145
+
146
+ async def another_weird_with_call ():
147
+ async with a ().b ():
148
+ ...
You can’t perform that action at this time.
0 commit comments