Enable 11 more categories in Ruff

* flake8-builtins ('A')
* flake8-blind-except ('BLE')
* flake8-copyright ('CPY')
* eradicate ('ERA')
* flake8-boolean-trap ('FBT')
* flake8-fixme ('FIX')
* flake8-implicit-str-concat ('ISC')
* pep8-naming ('N')
* flake8-use-pathlib ('PTH')
* flake8-self ('SLF')
* tryceratops ('TRY')
This commit is contained in:
Adam Turner
2025-01-14 14:43:02 +00:00
parent 3521cb60cf
commit c66d3e85d1
45 changed files with 154 additions and 106 deletions

View File

@@ -1,3 +1,4 @@
# NoQA: N999
from __future__ import annotations
from gettext import NullTranslations # NoQA: TC003

View File

@@ -42,13 +42,13 @@ class Baz:
class Qux:
@deco1
def __new__(self, name=None, age=None):
def __new__(cls, name=None, age=None):
pass
class _Metaclass(type):
@deco1
def __call__(self, name=None, age=None):
def __call__(cls, name=None, age=None):
pass

View File

@@ -57,12 +57,12 @@ class Bar:
"""docstring"""
@overload
def __init__(cls, x: int, y: int) -> None: ...
def __init__(self, x: int, y: int) -> None: ...
@overload
def __init__(cls, x: str, y: str) -> None: ...
def __init__(self, x: str, y: str) -> None: ...
def __init__(cls, x, y):
def __init__(self, x, y):
pass

View File

@@ -7,7 +7,7 @@ class Foo:
@classmethod
@property
def prop2(self) -> int:
def prop2(cls) -> int:
"""docstring"""
@property
@@ -17,6 +17,6 @@ class Foo:
@classmethod
@property
def prop2_with_type_comment(self):
def prop2_with_type_comment(cls):
# type: () -> int
"""docstring"""

View File

@@ -6,7 +6,7 @@ module with trailing underscores everywhere
class class_:
"""Class"""
def method_(_arg):
def method_(_arg): # NoQA: N805
"""Method"""
pass

View File

@@ -2,7 +2,7 @@
submodule
"""
raise RuntimeError('This module should not get imported') # NoQA: EM101
raise RuntimeError('This module should not get imported') # NoQA: EM101,TRY003
def decorator(f):

View File

@@ -71,7 +71,7 @@ def test_build_all(requests_head, make_app, nonascii_srcdir, buildername):
def test_root_doc_not_found(tmp_path, make_app):
(tmp_path / 'conf.py').touch()
assert os.listdir(tmp_path) == ['conf.py']
assert [p.name for p in tmp_path.iterdir()] == ['conf.py']
app = make_app('dummy', srcdir=tmp_path)
with pytest.raises(SphinxError):

View File

@@ -2,7 +2,6 @@
from __future__ import annotations
import os
import re
import pytest
@@ -309,7 +308,7 @@ def test_numfig_without_numbered_toctree(
index = re.sub(':numbered:.*', '', index)
(app.srcdir / 'index.rst').write_text(index, encoding='utf8')
if not os.listdir(app.outdir):
if not list(app.outdir.iterdir()):
app.build()
check_xpath(cached_etree_parse(app.outdir / fname), fname, path, check, be_found)

View File

@@ -2141,10 +2141,7 @@ def test_latex_code_role(app):
r'\PYG{k}{pass}'
)
assert (
r'Inline \sphinxcode{\sphinxupquote{%'
+ '\n'
+ common_content
+ '%\n}} code block'
'Inline \\sphinxcode{\\sphinxupquote{%\n' + common_content + '%\n}} code block'
) in content
assert (
r'\begin{sphinxVerbatim}[commandchars=\\\{\}]'

View File

@@ -260,7 +260,7 @@ def test_format_signature(app):
def foo1(self, b, *c):
pass
def foo2(b, *c):
def foo2(b, *c): # NoQA: N805
pass
def foo3(self, d='\n'):

View File

@@ -33,12 +33,12 @@ def _private_undoc():
pass
def __special_doc__():
def __special_doc__(): # NoQA: N807
"""module.__special_doc__.DOCSTRING"""
pass
def __special_undoc__():
def __special_undoc__(): # NoQA: N807
pass

View File

@@ -24,6 +24,7 @@ from sphinx.util.nodes import NodeMatcher
if TYPE_CHECKING:
from io import StringIO
from pathlib import Path
_CATALOG_LOCALE = 'xx'
@@ -47,9 +48,9 @@ def write_mo(pathname, po):
return mofile.write_mo(f, po)
def _set_mtime_ns(target: str | os.PathLike[str], value: int) -> int:
def _set_mtime_ns(target: Path, value: int) -> int:
os.utime(target, ns=(value, value))
return os.stat(target).st_mtime_ns
return target.stat().st_mtime_ns
def _get_bom_intl_path(app):

View File

@@ -85,7 +85,7 @@ def test_progress_message(app):
# skipping case
with progress_message('testing'):
raise SkipProgressMessage('Reason: %s', 'error') # NoQA: EM101
raise SkipProgressMessage('Reason: %s', 'error') # NoQA: EM101,TRY003
output = strip_colors(app.status.getvalue())
assert 'testing... skipped\nReason: error\n' in output
@@ -93,7 +93,7 @@ def test_progress_message(app):
# error case
try:
with progress_message('testing'):
raise RuntimeError
raise RuntimeError # NoQA: TRY301
except Exception:
pass

View File

@@ -40,32 +40,32 @@ def test_register_node():
assert not hasattr(nodes.SparseNodeVisitor, 'depart_custom_node')
def test_SphinxFileOutput(tmpdir):
def test_SphinxFileOutput(tmp_path):
content = 'Hello Sphinx World'
# write test.txt at first
filename = str(tmpdir / 'test.txt')
output = SphinxFileOutput(destination_path=filename)
filename = tmp_path / 'test.txt'
output = SphinxFileOutput(destination_path=str(filename))
output.write(content)
os.utime(filename, ns=(0, 0))
# overwrite it again
output.write(content)
assert os.stat(filename).st_mtime_ns != 0 # updated
assert filename.stat().st_mtime_ns != 0 # updated
# write test2.txt at first
filename = str(tmpdir / 'test2.txt')
output = SphinxFileOutput(destination_path=filename, overwrite_if_changed=True)
filename = tmp_path / 'test2.txt'
output = SphinxFileOutput(destination_path=str(filename), overwrite_if_changed=True)
output.write(content)
os.utime(filename, ns=(0, 0))
# overwrite it again
output.write(content)
assert os.stat(filename).st_mtime_ns == 0 # not updated
assert filename.stat().st_mtime_ns == 0 # not updated
# overwrite it again (content changed)
output.write(content + '; content change')
assert os.stat(filename).st_mtime_ns != 0 # updated
assert filename.stat().st_mtime_ns != 0 # updated
@pytest.mark.sphinx('html', testroot='root')

View File

@@ -39,7 +39,7 @@ def test_catalog_outdated(tmp_path):
mo_file.write_text('#', encoding='utf8')
assert not cat.is_outdated() # if mo is exist and newer than po
new_mtime = os.stat(mo_file).st_mtime_ns - 10_000_000_000
new_mtime = mo_file.stat().st_mtime_ns - 10_000_000_000
os.utime(mo_file, ns=(new_mtime, new_mtime)) # to be outdated
assert cat.is_outdated() # if mo is exist and older than po
@@ -98,7 +98,7 @@ def test_format_date():
def test_format_date_timezone():
dt = datetime.datetime(2016, 8, 7, 5, 11, 17, 0, tzinfo=datetime.UTC)
if time.localtime(dt.timestamp()).tm_gmtoff == 0:
raise pytest.skip('Local time zone is GMT') # NoQA: EM101
raise pytest.skip('Local time zone is GMT') # NoQA: EM101,TRY003
fmt = '%Y-%m-%d %H:%M:%S'

View File

@@ -942,7 +942,7 @@ def test_unpartial():
def test_getdoc_inherited_classmethod():
class Foo:
@classmethod
def meth(self):
def meth(cls):
"""
Docstring
indented text
@@ -950,7 +950,7 @@ def test_getdoc_inherited_classmethod():
class Bar(Foo):
@classmethod
def meth(self):
def meth(cls):
# inherited classmethod
pass

View File

@@ -2,7 +2,6 @@
from __future__ import annotations
import os
from typing import TYPE_CHECKING
import pytest
@@ -94,10 +93,10 @@ def test_ambiguous_definition_warning(app):
def _write_appconfig(dir: Path, language: str, prefix: str | None = None) -> Path:
prefix = prefix or language
os.makedirs(dir / prefix, exist_ok=True)
(dir / prefix).mkdir(parents=True, exist_ok=True)
(dir / prefix / 'conf.py').write_text(f'language = "{language}"', encoding='utf8')
(dir / prefix / 'index.rst').write_text('index.rst', encoding='utf8')
assert sorted(os.listdir(dir / prefix)) == ['conf.py', 'index.rst']
assert sorted(p.name for p in (dir / prefix).iterdir()) == ['conf.py', 'index.rst']
assert (dir / prefix / 'index.rst').exists()
return dir / prefix