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

Support options from pydocstyle 6.2.0 and 6.3.0 #48

Merged
merged 3 commits into from
Jan 21, 2023
Merged
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
72 changes: 60 additions & 12 deletions flake8_docstrings.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,20 @@
"""
import re

supports_ignore_inline_noqa = False
supports_property_decorators = False
supports_ignore_self_only_init = False
try:
import pydocstyle as pep257

module_name = "pydocstyle"

pydocstyle_version = tuple(
int(num) for num in pep257.__version__.split(".")
)
supports_ignore_inline_noqa = pydocstyle_version >= (6, 0, 0)
supports_property_decorators = pydocstyle_version >= (6, 2, 0)
supports_ignore_self_only_init = pydocstyle_version >= (6, 3, 0)
except ImportError:
import pep257

Expand Down Expand Up @@ -94,6 +104,33 @@ def add_options(cls, parser):
),
)

if supports_property_decorators:
from pydocstyle.config import ConfigurationParser

default_property_decorators = (
ConfigurationParser.DEFAULT_PROPERTY_DECORATORS
)
parser.add_option(
"--property-decorators",
action="store",
parse_from_config=True,
default=default_property_decorators,
help=(
"consider any method decorated with one of these "
"decorators as a property, and consequently allow "
"a docstring which is not in imperative mood; default "
f"is --property-decorators='{default_property_decorators}'"
),
)

if supports_ignore_self_only_init:
parser.add_option(
"--ignore-self-only-init",
action="store_true",
parse_from_config=True,
help="ignore __init__ methods which only have a self param.",
)

@classmethod
def parse_options(cls, options):
"""Parse the configuration options given to flake8."""
Expand All @@ -103,21 +140,32 @@ def parse_options(cls, options):
if options.ignore_decorators
else None
)
if supports_property_decorators:
cls.property_decorators = options.property_decorators
if supports_ignore_self_only_init:
cls.ignore_self_only_init = options.ignore_self_only_init

def _call_check_source(self):
try:
return self.checker.check_source(
self.source,
self.filename,
ignore_decorators=self.ignore_decorators,
ignore_inline_noqa=True,
)
except TypeError: # for versions of pydocstyle 5.1.1 and below
return self.checker.check_source(
self.source,
self.filename,
ignore_decorators=self.ignore_decorators,
check_source_kwargs = {}
if supports_ignore_inline_noqa:
check_source_kwargs["ignore_inline_noqa"] = True
if supports_property_decorators:
check_source_kwargs["property_decorators"] = (
set(self.property_decorators.split(","))
if self.property_decorators
else None
)
if supports_ignore_self_only_init:
check_source_kwargs[
"ignore_self_only_init"
] = self.ignore_self_only_init

return self.checker.check_source(
self.source,
self.filename,
ignore_decorators=self.ignore_decorators,
**check_source_kwargs,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for using kwargs here. pydocstyle has had a bunch of issues with other integrations using positional args

)

def _check_source(self):
try:
Expand Down