Skip to content

Commit

Permalink
Merge pull request #48 from NMertsch/main
Browse files Browse the repository at this point in the history
Support options from pydocstyle 6.2.0 and 6.3.0
  • Loading branch information
sigmavirus24 committed Jan 21, 2023
2 parents 76463dc + 85c3467 commit e8c4f6c
Showing 1 changed file with 60 additions and 12 deletions.
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,
)

def _check_source(self):
try:
Expand Down

0 comments on commit e8c4f6c

Please sign in to comment.