-
-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ASYNC912: timeout/cancelscope with only conditional checkpoints #242
Changes from 5 commits
94f2a5a
3114c7e
231ba74
e7c5ccd
4720f85
df403c3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,7 +30,6 @@ | |
from . import ( | ||
visitor2xx, | ||
visitor91x, | ||
visitor100, | ||
visitor101, | ||
visitor102, | ||
visitor103_104, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -51,13 +51,19 @@ def error_class_cst(error_class: type[T_CST]) -> type[T_CST]: | |
|
||
|
||
def disabled_by_default(error_class: type[T_EITHER]) -> type[T_EITHER]: | ||
"""Default-disables all error codes in a class.""" | ||
assert error_class.error_codes # type: ignore[attr-defined] | ||
default_disabled_error_codes.extend( | ||
error_class.error_codes # type: ignore[attr-defined] | ||
) | ||
return error_class | ||
|
||
|
||
def disable_codes_by_default(*codes: str) -> None: | ||
"""Default-disables only specified codes.""" | ||
default_disabled_error_codes.extend(codes) | ||
|
||
|
||
def utility_visitor(c: type[T]) -> type[T]: | ||
assert not hasattr(c, "error_codes") | ||
c.error_codes = {} | ||
|
@@ -320,13 +326,20 @@ class AttributeCall(NamedTuple): | |
def with_has_call( | ||
node: cst.With, *names: str, base: Iterable[str] = ("trio", "anyio") | ||
) -> list[AttributeCall]: | ||
if isinstance(base, str): | ||
base = (base,) # pragma: no cover | ||
|
||
for b in base: | ||
if b.count(".") > 1: # pragma: no cover | ||
raise NotImplementedError("Does not support 3-module bases atm.") | ||
|
||
res_list: list[AttributeCall] = [] | ||
for item in node.items: | ||
if res := m.extract( | ||
item.item, | ||
m.Call( | ||
func=m.Attribute( | ||
value=m.SaveMatchedNode(m.Name(), name="library"), | ||
value=m.SaveMatchedNode(m.Name() | m.Attribute(), name="library"), | ||
attr=m.SaveMatchedNode( | ||
oneof_names(*names), | ||
name="function", | ||
|
@@ -335,12 +348,30 @@ def with_has_call( | |
), | ||
): | ||
assert isinstance(item.item, cst.Call) | ||
assert isinstance(res["library"], cst.Name) | ||
assert isinstance(res["library"], (cst.Name, cst.Attribute)) | ||
assert isinstance(res["function"], cst.Name) | ||
if res["library"].value not in base: | ||
library_node = res["library"] | ||
for library_str in base: | ||
if ( | ||
isinstance(library_node, cst.Name) | ||
and library_str == library_node.value | ||
): | ||
break | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These checks suggest to me that using a libcst matcher might be more efficient. Could we have a helper function which parses a string ( There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes, though sounds complicated to engineer. I'll give it a try and see if I get anywhere easily, otherwise throw in a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ended up being straightforward to write, but got sidetracked by Instagram/LibCST#1143 |
||
if ( | ||
isinstance(library_node, cst.Attribute) | ||
and isinstance(library_node.value, cst.Name) | ||
and "." in library_str | ||
): | ||
base_1, base_2 = library_str.split(".") | ||
if ( | ||
library_node.attr.value == base_2 | ||
and library_node.value.value == base_1 | ||
): | ||
break | ||
else: | ||
continue | ||
res_list.append( | ||
AttributeCall(item.item, res["library"].value, res["function"].value) | ||
AttributeCall(item.item, library_str, res["function"].value) | ||
) | ||
return res_list | ||
|
||
|
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's not great that there's duplication of logic between the visitors (it confused me for a bit while developing). I originally expected all visitors to be rewritten to use libcst, but given that's not going to happen anytime soon (or at all), I should probably refactor these two and put common code in a parent class.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense to me 👍