Only use dummy implementation logic for functions and classes (#4066)
Fixes #4063
This commit is contained in:
parent
67b23d7185
commit
9aea9768cb
@ -20,6 +20,8 @@
|
|||||||
- Allow empty lines at the beginning of all blocks, except immediately before a
|
- Allow empty lines at the beginning of all blocks, except immediately before a
|
||||||
docstring (#4060)
|
docstring (#4060)
|
||||||
- Fix crash in preview mode when using a short `--line-length` (#4086)
|
- Fix crash in preview mode when using a short `--line-length` (#4086)
|
||||||
|
- Keep suites consisting of only an ellipsis on their own lines if they are not
|
||||||
|
functions or class definitions (#4066)
|
||||||
|
|
||||||
### Configuration
|
### Configuration
|
||||||
|
|
||||||
|
@ -286,7 +286,7 @@ def visit_suite(self, node: Node) -> Iterator[Line]:
|
|||||||
"""Visit a suite."""
|
"""Visit a suite."""
|
||||||
if (
|
if (
|
||||||
self.mode.is_pyi or Preview.dummy_implementations in self.mode
|
self.mode.is_pyi or Preview.dummy_implementations in self.mode
|
||||||
) and is_stub_suite(node):
|
) and is_stub_suite(node, self.mode):
|
||||||
yield from self.visit(node.children[2])
|
yield from self.visit(node.children[2])
|
||||||
else:
|
else:
|
||||||
yield from self.visit_default(node)
|
yield from self.visit_default(node)
|
||||||
@ -314,7 +314,7 @@ def visit_simple_stmt(self, node: Node) -> Iterator[Line]:
|
|||||||
if (
|
if (
|
||||||
not (self.mode.is_pyi or Preview.dummy_implementations in self.mode)
|
not (self.mode.is_pyi or Preview.dummy_implementations in self.mode)
|
||||||
or not node.parent
|
or not node.parent
|
||||||
or not is_stub_suite(node.parent)
|
or not is_stub_suite(node.parent, self.mode)
|
||||||
):
|
):
|
||||||
yield from self.line()
|
yield from self.line()
|
||||||
yield from self.visit_default(node)
|
yield from self.visit_default(node)
|
||||||
|
@ -736,8 +736,15 @@ def is_funcdef(node: Node) -> bool:
|
|||||||
return node.type == syms.funcdef
|
return node.type == syms.funcdef
|
||||||
|
|
||||||
|
|
||||||
def is_stub_suite(node: Node) -> bool:
|
def is_stub_suite(node: Node, mode: Mode) -> bool:
|
||||||
"""Return True if `node` is a suite with a stub body."""
|
"""Return True if `node` is a suite with a stub body."""
|
||||||
|
if node.parent is not None:
|
||||||
|
if Preview.dummy_implementations in mode and node.parent.type not in (
|
||||||
|
syms.funcdef,
|
||||||
|
syms.async_funcdef,
|
||||||
|
syms.classdef,
|
||||||
|
):
|
||||||
|
return False
|
||||||
|
|
||||||
# If there is a comment, we want to keep it.
|
# If there is a comment, we want to keep it.
|
||||||
if node.prefix.strip():
|
if node.prefix.strip():
|
||||||
|
@ -1,9 +1,11 @@
|
|||||||
# flags: --preview
|
# flags: --preview
|
||||||
from typing import NoReturn, Protocol, Union, overload
|
from typing import NoReturn, Protocol, Union, overload
|
||||||
|
|
||||||
|
class Empty:
|
||||||
|
...
|
||||||
|
|
||||||
def dummy(a): ...
|
def dummy(a): ...
|
||||||
def other(b): ...
|
async def other(b): ...
|
||||||
|
|
||||||
|
|
||||||
@overload
|
@overload
|
||||||
@ -48,13 +50,22 @@ def b(arg: Union[int, str, object]) -> Union[int, str]:
|
|||||||
raise TypeError
|
raise TypeError
|
||||||
return arg
|
return arg
|
||||||
|
|
||||||
|
def has_comment():
|
||||||
|
... # still a dummy
|
||||||
|
|
||||||
|
if some_condition:
|
||||||
|
...
|
||||||
|
|
||||||
# output
|
# output
|
||||||
|
|
||||||
from typing import NoReturn, Protocol, Union, overload
|
from typing import NoReturn, Protocol, Union, overload
|
||||||
|
|
||||||
|
|
||||||
|
class Empty: ...
|
||||||
|
|
||||||
|
|
||||||
def dummy(a): ...
|
def dummy(a): ...
|
||||||
def other(b): ...
|
async def other(b): ...
|
||||||
|
|
||||||
|
|
||||||
@overload
|
@overload
|
||||||
@ -98,3 +109,10 @@ def b(arg: Union[int, str, object]) -> Union[int, str]:
|
|||||||
if not isinstance(arg, (int, str)):
|
if not isinstance(arg, (int, str)):
|
||||||
raise TypeError
|
raise TypeError
|
||||||
return arg
|
return arg
|
||||||
|
|
||||||
|
|
||||||
|
def has_comment(): ... # still a dummy
|
||||||
|
|
||||||
|
|
||||||
|
if some_condition:
|
||||||
|
...
|
||||||
|
Loading…
Reference in New Issue
Block a user