Remove is_function_or_class helper footgun (#4133)
This is a no-op change. That function was not a good way to tell if something is a function or a class, since it basically only worked for async functions by accident (the parent of a suite / simple_stmt of async function body is a funcdef).
This commit is contained in:
parent
269190274b
commit
4ceed0b958
@ -42,12 +42,12 @@
|
|||||||
is_atom_with_invisible_parens,
|
is_atom_with_invisible_parens,
|
||||||
is_docstring,
|
is_docstring,
|
||||||
is_empty_tuple,
|
is_empty_tuple,
|
||||||
is_function_or_class,
|
|
||||||
is_lpar_token,
|
is_lpar_token,
|
||||||
is_multiline_string,
|
is_multiline_string,
|
||||||
is_name_token,
|
is_name_token,
|
||||||
is_one_sequence_between,
|
is_one_sequence_between,
|
||||||
is_one_tuple,
|
is_one_tuple,
|
||||||
|
is_parent_function_or_class,
|
||||||
is_rpar_token,
|
is_rpar_token,
|
||||||
is_stub_body,
|
is_stub_body,
|
||||||
is_stub_suite,
|
is_stub_suite,
|
||||||
@ -302,7 +302,7 @@ def visit_simple_stmt(self, node: Node) -> Iterator[Line]:
|
|||||||
|
|
||||||
if node.parent and node.parent.type in STATEMENT:
|
if node.parent and node.parent.type in STATEMENT:
|
||||||
if Preview.dummy_implementations in self.mode:
|
if Preview.dummy_implementations in self.mode:
|
||||||
condition = is_function_or_class(node.parent)
|
condition = is_parent_function_or_class(node)
|
||||||
else:
|
else:
|
||||||
condition = self.mode.is_pyi
|
condition = self.mode.is_pyi
|
||||||
if condition and is_stub_body(node):
|
if condition and is_stub_body(node):
|
||||||
|
@ -742,6 +742,13 @@ def is_multiline_string(leaf: Leaf) -> bool:
|
|||||||
return has_triple_quotes(leaf.value) and "\n" in leaf.value
|
return has_triple_quotes(leaf.value) and "\n" in leaf.value
|
||||||
|
|
||||||
|
|
||||||
|
def is_parent_function_or_class(node: Node) -> bool:
|
||||||
|
assert node.type in {syms.suite, syms.simple_stmt}
|
||||||
|
assert node.parent is not None
|
||||||
|
# Note this works for suites / simple_stmts in async def as well
|
||||||
|
return node.parent.type in {syms.funcdef, syms.classdef}
|
||||||
|
|
||||||
|
|
||||||
def is_function_or_class(node: Node) -> bool:
|
def is_function_or_class(node: Node) -> bool:
|
||||||
return node.type in {syms.funcdef, syms.classdef, syms.async_funcdef}
|
return node.type in {syms.funcdef, syms.classdef, syms.async_funcdef}
|
||||||
|
|
||||||
@ -751,7 +758,7 @@ def is_stub_suite(node: Node, mode: Mode) -> bool:
|
|||||||
if (
|
if (
|
||||||
node.parent is not None
|
node.parent is not None
|
||||||
and Preview.dummy_implementations in mode
|
and Preview.dummy_implementations in mode
|
||||||
and not is_function_or_class(node.parent)
|
and not is_parent_function_or_class(node)
|
||||||
):
|
):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
@ -58,6 +58,17 @@ def has_comment():
|
|||||||
|
|
||||||
if already_dummy: ...
|
if already_dummy: ...
|
||||||
|
|
||||||
|
class AsyncCls:
|
||||||
|
async def async_method(self):
|
||||||
|
...
|
||||||
|
|
||||||
|
async def async_function(self):
|
||||||
|
...
|
||||||
|
|
||||||
|
@decorated
|
||||||
|
async def async_function(self):
|
||||||
|
...
|
||||||
|
|
||||||
# output
|
# output
|
||||||
|
|
||||||
from typing import NoReturn, Protocol, Union, overload
|
from typing import NoReturn, Protocol, Union, overload
|
||||||
@ -121,3 +132,14 @@ def has_comment(): ... # still a dummy
|
|||||||
|
|
||||||
if already_dummy:
|
if already_dummy:
|
||||||
...
|
...
|
||||||
|
|
||||||
|
|
||||||
|
class AsyncCls:
|
||||||
|
async def async_method(self): ...
|
||||||
|
|
||||||
|
|
||||||
|
async def async_function(self): ...
|
||||||
|
|
||||||
|
|
||||||
|
@decorated
|
||||||
|
async def async_function(self): ...
|
||||||
|
Loading…
Reference in New Issue
Block a user