Skip to content

Commit 79eada8

Browse files
committed
Enable and fix many Ruff lints
1 parent 1aa5dcc commit 79eada8

31 files changed

+110
-106
lines changed

properdocs/__main__.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import textwrap
88
import traceback
99
import warnings
10+
from typing import ClassVar
1011

1112
import click
1213

@@ -39,7 +40,7 @@ def _showwarning(message, category, filename, lineno, file=None, line=None):
3940
stack = [frame for frame in traceback.extract_stack() if frame.line][-4:-2]
4041
# Make sure the actual affected file's name is still present (the case of syntax warning):
4142
if not any(frame.filename == filename for frame in stack):
42-
stack = stack[-1:] + [traceback.FrameSummary(filename, lineno, '')]
43+
stack = [*stack[-1:], traceback.FrameSummary(filename, lineno, '')]
4344

4445
tb = ''.join(traceback.format_list(stack))
4546
except Exception:
@@ -62,7 +63,7 @@ def _enable_warnings():
6263

6364

6465
class ColorFormatter(logging.Formatter):
65-
colors = {
66+
colors: ClassVar = {
6667
'CRITICAL': 'red',
6768
'ERROR': 'red',
6869
'WARNING': 'yellow',

properdocs/commands/build.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,7 @@ def _build_template(
8787
output = template.render(context)
8888

8989
# Run `post_template` plugin events.
90-
output = config.plugins.on_post_template(output, template_name=name, config=config)
91-
92-
return output
90+
return config.plugins.on_post_template(output, template_name=name, config=config)
9391

9492

9593
def _build_theme_template(
@@ -321,8 +319,8 @@ def build(config: ProperDocsConfig, *, serve_url: str | None = None, dirty: bool
321319
if excluded:
322320
log.info(
323321
"The following pages are being built only for the preview "
324-
"but will be excluded from `properdocs build` per `draft_docs` config:\n - "
325-
+ "\n - ".join(excluded)
322+
"but will be excluded from `properdocs build` per `draft_docs` config:\n - %s",
323+
"\n - ".join(excluded),
326324
)
327325

328326
# Run `env` plugin events.

properdocs/commands/get_deps.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
log = logging.getLogger(__name__)
2828

2929

30-
class YamlLoaderWithSuppressions(SafeLoader): # type: ignore
30+
class YamlLoaderWithSuppressions(SafeLoader): # type: ignore # noqa: PGH003
3131
pass
3232

3333

properdocs/commands/gh_deploy.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import subprocess
77
from typing import TYPE_CHECKING
88

9-
import ghp_import # type: ignore
9+
import ghp_import # type: ignore[import-untyped]
1010
from packaging import version
1111

1212
import properdocs
@@ -43,8 +43,7 @@ def _get_current_sha(repo_path) -> str:
4343
)
4444

4545
stdout, _ = proc.communicate()
46-
sha = stdout.decode('utf-8').strip()
47-
return sha
46+
return stdout.decode('utf-8').strip()
4847

4948

5049
def _get_remote_url(remote_name: str) -> tuple[str, str] | tuple[None, None]:
@@ -78,7 +77,9 @@ def _check_version(branch: str) -> None:
7877

7978
stdout, _ = proc.communicate()
8079
msg = stdout.decode('utf-8').strip()
81-
m = re.search(r'\d+(\.\d+)+((a|b|rc)\d+)?(\.post\d+)?(\.dev\d+)?', msg, re.X | re.I)
80+
m = re.search(
81+
r'\d+(\.\d+)+((a|b|rc)\d+)?(\.post\d+)?(\.dev\d+)?', msg, re.VERBOSE | re.IGNORECASE
82+
)
8283
previousv = version.parse(m.group()) if m else None
8384
currentv = version.parse(properdocs.__version__)
8485
if not previousv:
@@ -163,7 +164,6 @@ def gh_deploy(
163164
log.info('Your documentation should be available shortly.')
164165
else:
165166
username, repo = path.split('/', 1)
166-
if repo.endswith('.git'):
167-
repo = repo[: -len('.git')]
167+
repo = repo.removesuffix('.git')
168168
url = f'https://{username}.github.io/{repo}/'
169169
log.info(f"Your documentation should shortly be available at: {url}")

properdocs/config/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
from properdocs.config.base import Config, load_config
22

3-
__all__ = ['load_config', 'Config']
3+
__all__ = ['Config', 'load_config']

properdocs/config/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ def __init_subclass__(cls):
136136
"All values are required, or can be wrapped into config_options.Optional"
137137
)
138138

139-
def __new__(cls, *args, **kwargs) -> Config:
139+
def __new__(cls, *args, **kwargs) -> Config: # noqa: PYI034
140140
"""Compatibility: allow referring to `LegacyConfig(...)` constructor as `Config(...)`."""
141141
if cls is Config:
142142
return LegacyConfig(*args, **kwargs)

properdocs/config/config_options.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ def pre_validation(self, config: Config, key_name: str):
9494
def run_validation(self, value: object) -> SomeConfig:
9595
config = self.config_class(config_file_path=self._config_file_path)
9696
try:
97-
config.load_dict(value) # type: ignore
97+
config.load_dict(value) # type: ignore[arg-type]
9898
failed, warnings = config.validate()
9999
except ConfigurationError as e:
100100
raise ValidationError(str(e))
@@ -359,7 +359,7 @@ def __init__(self, choices: Collection[T], default: T | None = None, **kwargs) -
359359
def run_validation(self, value: object) -> T:
360360
if value not in self.choices:
361361
raise ValidationError(f"Expected one of: {self.choices} but received: {value!r}")
362-
return value # type: ignore
362+
return value # type: ignore[return-value]
363363

364364

365365
class Deprecated(BaseConfigOption):
@@ -536,7 +536,7 @@ def run_validation(self, value: object) -> T | None:
536536
return self.option.validate(value)
537537

538538
def post_validation(self, config: Config, key_name: str):
539-
result = self.option.post_validation(config, key_name) # type: ignore
539+
result = self.option.post_validation(config, key_name) # type: ignore[func-returns-value]
540540
self.warnings = self.option.warnings
541541
return result
542542

properdocs/contrib/search/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ def get_lunr_supported_lang(self, lang):
3030
lang_part = fallback.get(lang_part, lang_part)
3131
if os.path.isfile(os.path.join(base_path, 'lunr-language', f'lunr.{lang_part}.js')):
3232
return lang_part
33+
return None
3334

3435
def run_validation(self, value: object):
3536
if isinstance(value, str):
@@ -70,7 +71,7 @@ def on_config(self, config: ProperDocsConfig, **kwargs) -> ProperDocsConfig:
7071
path = os.path.join(base_path, 'templates')
7172
config.theme.dirs.append(path)
7273
if 'search/main.js' not in config.extra_javascript:
73-
config.extra_javascript.append('search/main.js') # type: ignore
74+
config.extra_javascript.append('search/main.js')
7475
if self.config.lang is None:
7576
# lang setting undefined. Set default based on theme locale
7677
validate = _PluginConfig.lang.run_validation

properdocs/contrib/search/search_index.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
from properdocs.structure.toc import AnchorLink, TableOfContents
1414

1515
try:
16-
from lunr import lunr # type: ignore
16+
from lunr import lunr # type: ignore[import-not-found]
1717

1818
haslunrpy = True
1919
except ImportError:

properdocs/localization.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
has_babel = True
2020
except ImportError: # pragma: no cover
21-
from properdocs.utils.babel_stub import Locale, UnknownLocaleError # type: ignore
21+
from properdocs.utils.babel_stub import Locale, UnknownLocaleError # type: ignore[assignment]
2222

2323
has_babel = False
2424

0 commit comments

Comments
 (0)