Skip to content

Commit

Permalink
Don't enforce returns and yields in abstract methods
Browse files Browse the repository at this point in the history
  • Loading branch information
charliermarsh committed Aug 9, 2024
1 parent bc5b9b8 commit f026e05
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,17 @@ def foo(self) -> int:
x
"""
raise NotImplementedError


import abc


class A(metaclass=abc.abcmeta):
@abc.abstractmethod
def f(self):
"""Lorem ipsum
Returns:
dict: The values
"""
return
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,19 @@ def bar(self) -> str:
A number
"""
print('test')


import abc


class A(metaclass=abc.abcmeta):
@abc.abstractmethod
def f(self):
"""Lorem ipsum
Returns
-------
dict:
The values
"""
return
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use ruff_python_ast::helpers::map_callable;
use ruff_python_ast::name::QualifiedName;
use ruff_python_ast::visitor::Visitor;
use ruff_python_ast::{self as ast, visitor, Expr, Stmt};
use ruff_python_semantic::analyze::function_type;
use ruff_python_semantic::analyze::{function_type, visibility};
use ruff_python_semantic::{Definition, SemanticModel};
use ruff_text_size::{Ranged, TextRange};

Expand Down Expand Up @@ -702,6 +702,11 @@ pub(crate) fn check_docstring(
return;
}

// Ignore abstract methods.
if visibility::is_abstract(&function_def.decorator_list, checker.semantic()) {
return;
}

// Prioritize the specified convention over the determined style.
let docstring_sections = match convention {
Some(Convention::Google) => {
Expand Down

0 comments on commit f026e05

Please sign in to comment.