Skip to content
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

Fix *arg and **kwarg handling for Google docstrings #1608

Merged
merged 1 commit into from Jan 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions pyproject.toml
Expand Up @@ -36,3 +36,6 @@ urls = { repository = "https://github.com/charliermarsh/ruff-lsp" }
[tool.maturin]
bindings = "bin"
strip = true

[tool.ruff.pydocstyle]
convention = "google"
45 changes: 38 additions & 7 deletions resources/test/fixtures/pydocstyle/D417.py
@@ -1,5 +1,5 @@
def f(x, y, z):
"""Do f.
"""Do something.

Args:
x: the value
Expand All @@ -12,7 +12,7 @@ def f(x, y, z):


def f(x, y, z):
"""Do f.
"""Do something.

Args:
x:
Expand All @@ -25,7 +25,7 @@ def f(x, y, z):


def f(x, y, z):
"""Do f.
"""Do something.

Args:
x:
Expand All @@ -37,7 +37,7 @@ def f(x, y, z):


def f(x, y, z):
"""Do f.
"""Do something.

Args:
x: the value def
Expand All @@ -50,7 +50,7 @@ def f(x, y, z):


def f(x, y, z):
"""Do f.
"""Do something.

Args:
x: the value
Expand All @@ -63,7 +63,7 @@ def f(x, y, z):


def f(x, y, z):
"""Do g.
"""Do something.

Args:
x: the value
Expand All @@ -75,10 +75,41 @@ def f(x, y, z):


def f(x, y, z):
"""Do h.
"""Do something.

Args:
x: the value
z: A final argument
"""
return x


def f(x, *args, **kwargs):
"""Do something.

Args:
x: the value
*args: variable arguments
**kwargs: keyword arguments
"""
return x


def f(x, *args, **kwargs):
"""Do something.

Args:
*args: variable arguments
**kwargs: keyword arguments
"""
return x


def f(x, *args, **kwargs):
"""Do something.

Args:
x: the value
**kwargs: keyword arguments
"""
return x
2 changes: 1 addition & 1 deletion src/pydocstyle/plugins.rs
Expand Up @@ -1413,7 +1413,7 @@ fn missing_args(checker: &mut Checker, docstring: &Docstring, docstrings_args: &

// See: `GOOGLE_ARGS_REGEX` in `pydocstyle/checker.py`.
static GOOGLE_ARGS_REGEX: Lazy<Regex> =
Lazy::new(|| Regex::new(r"^\s*(\w+)\s*(\(.*?\))?\s*:.+").unwrap());
Lazy::new(|| Regex::new(r"^\s*(\*?\*?\w+)\s*(\(.*?\))?\s*:.+").unwrap());

fn args_section(checker: &mut Checker, docstring: &Docstring, context: &SectionContext) {
let mut matches = Vec::new();
Expand Down
22 changes: 22 additions & 0 deletions src/pydocstyle/snapshots/ruff__pydocstyle__tests__d417_google.snap
Expand Up @@ -85,4 +85,26 @@ expression: checks
column: 12
fix: ~
parent: ~
- kind:
DocumentAllArguments:
- x
location:
row: 98
column: 0
end_location:
row: 105
column: 12
fix: ~
parent: ~
- kind:
DocumentAllArguments:
- "*args"
location:
row: 108
column: 0
end_location:
row: 115
column: 12
fix: ~
parent: ~

Expand Up @@ -37,4 +37,26 @@ expression: checks
column: 12
fix: ~
parent: ~
- kind:
DocumentAllArguments:
- x
location:
row: 98
column: 0
end_location:
row: 105
column: 12
fix: ~
parent: ~
- kind:
DocumentAllArguments:
- "*args"
location:
row: 108
column: 0
end_location:
row: 115
column: 12
fix: ~
parent: ~