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_docstring,
|
||||
is_empty_tuple,
|
||||
is_function_or_class,
|
||||
is_lpar_token,
|
||||
is_multiline_string,
|
||||
is_name_token,
|
||||
is_one_sequence_between,
|
||||
is_one_tuple,
|
||||
is_parent_function_or_class,
|
||||
is_rpar_token,
|
||||
is_stub_body,
|
||||
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 Preview.dummy_implementations in self.mode:
|
||||
condition = is_function_or_class(node.parent)
|
||||
condition = is_parent_function_or_class(node)
|
||||
else:
|
||||
condition = self.mode.is_pyi
|
||||
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
|
||||
|
||||
|
||||
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:
|
||||
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 (
|
||||
node.parent is not None
|
||||
and Preview.dummy_implementations in mode
|
||||
and not is_function_or_class(node.parent)
|
||||
and not is_parent_function_or_class(node)
|
||||
):
|
||||
return False
|
||||
|
||||
|
@ -58,6 +58,17 @@ def has_comment():
|
||||
|
||||
if already_dummy: ...
|
||||
|
||||
class AsyncCls:
|
||||
async def async_method(self):
|
||||
...
|
||||
|
||||
async def async_function(self):
|
||||
...
|
||||
|
||||
@decorated
|
||||
async def async_function(self):
|
||||
...
|
||||
|
||||
# output
|
||||
|
||||
from typing import NoReturn, Protocol, Union, overload
|
||||
@ -121,3 +132,14 @@ def has_comment(): ... # still a 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