From 24b19bfe8a44750c9d7d94bac85bd5494a001aa6 Mon Sep 17 00:00:00 2001 From: David Lord Date: Fri, 2 Feb 2024 08:42:59 -0800 Subject: [PATCH 1/2] update .gitignore --- .gitignore | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/.gitignore b/.gitignore index b48a303d..dbaee290 100644 --- a/.gitignore +++ b/.gitignore @@ -1,17 +1,13 @@ /.idea/ /.vscode/ -/env/ -/venv/ +/.venv*/ +/venv*/ __pycache__/ -*.pyc *.so *.egg-info/ /build/ /dist/ -/.pytest_cache/ /.tox/ -.coverage -.coverage.* +/.coverage* /htmlcov/ /docs/_build/ -/.mypy_cache/ From 81695293c0b972db0531437bf2f3a13bc3ffc7de Mon Sep 17 00:00:00 2001 From: David Lord Date: Fri, 2 Feb 2024 08:47:08 -0800 Subject: [PATCH 2/2] use ruff lint and format --- .flake8 | 22 ---------------------- .pre-commit-config.yaml | 26 ++++++-------------------- pyproject.toml | 22 ++++++++++++++++++++++ src/markupsafe/__init__.py | 14 ++++++++------ tests/conftest.py | 9 ++++++--- tests/test_markupsafe.py | 6 +++--- 6 files changed, 45 insertions(+), 54 deletions(-) delete mode 100644 .flake8 diff --git a/.flake8 b/.flake8 deleted file mode 100644 index 07b9d8da..00000000 --- a/.flake8 +++ /dev/null @@ -1,22 +0,0 @@ -[flake8] -extend-select = - # bugbear - B - # bugbear opinions - B9 - # implicit str concat - ISC -extend-ignore = - # slice notation whitespace, invalid - E203 - # line length, handled by bugbear B950 - E501 - # bare except, handled by bugbear B001 - E722 - # zip with strict=, requires python >= 3.10 - B905 - # string formatting opinion, B028 renamed to B907 - B028 - B907 -# up to 88 allowed by bugbear B950 -max-line-length = 80 diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index eed37a46..a5d18eca 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,30 +1,16 @@ ci: autoupdate_schedule: monthly repos: - - repo: https://github.com/asottile/pyupgrade - rev: v3.15.0 + - repo: https://github.com/astral-sh/ruff-pre-commit + rev: v0.2.0 hooks: - - id: pyupgrade - args: ["--py38-plus"] - - repo: https://github.com/asottile/reorder-python-imports - rev: v3.12.0 - hooks: - - id: reorder-python-imports - args: ["--application-directories", "src"] - - repo: https://github.com/psf/black - rev: 24.1.1 - hooks: - - id: black - - repo: https://github.com/PyCQA/flake8 - rev: 7.0.0 - hooks: - - id: flake8 - additional_dependencies: - - flake8-bugbear - - flake8-implicit-str-concat + - id: ruff + - id: ruff-format - repo: https://github.com/pre-commit/pre-commit-hooks rev: v4.5.0 hooks: + - id: check-merge-conflict + - id: debug-statements - id: fix-byte-order-marker - id: trailing-whitespace - id: end-of-file-fixer diff --git a/pyproject.toml b/pyproject.toml index d2b5728e..83a718b9 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -53,3 +53,25 @@ strict = true pythonVersion = "3.8" include = ["src/markupsafe", "tests"] typeCheckingMode = "basic" + +[tool.ruff] +src = ["src"] +fix = true +unsafe-fixes = true +show-fixes = true +output-format = "full" + +[tool.ruff.lint] +select = [ + "B", # flake8-bugbear + "E", # pycodestyle error + "F", # pyflakes + "I", # isort + "UP", # pyupgrade + "W", # pycodestyle warning +] +ignore-init-module-imports = true + +[tool.ruff.lint.isort] +force-single-line = true +order-by-type = false diff --git a/src/markupsafe/__init__.py b/src/markupsafe/__init__.py index cd14a141..cbc4f555 100644 --- a/src/markupsafe/__init__.py +++ b/src/markupsafe/__init__.py @@ -9,10 +9,12 @@ import typing_extensions as te class HasHTML(te.Protocol): - def __html__(self, /) -> str: ... + def __html__(self, /) -> str: + ... class TPEscape(te.Protocol): - def __call__(self, s: t.Any, /) -> Markup: ... + def __call__(self, s: t.Any, /) -> Markup: + ... class Markup(str): @@ -237,14 +239,14 @@ def removesuffix(self, suffix: str) -> te.Self: return self.__class__(super().removesuffix(suffix)) def partition(self, sep: str, /) -> tuple[te.Self, te.Self, te.Self]: - l, s, r = super().partition(sep) + left, sep, right = super().partition(sep) cls = self.__class__ - return cls(l), cls(s), cls(r) + return cls(left), cls(sep), cls(right) def rpartition(self, sep: str, /) -> tuple[te.Self, te.Self, te.Self]: - l, s, r = super().rpartition(sep) + left, sep, right = super().rpartition(sep) cls = self.__class__ - return cls(l), cls(s), cls(r) + return cls(left), cls(sep), cls(right) def format(self, *args: t.Any, **kwargs: t.Any) -> te.Self: formatter = EscapeFormatter(self.escape) diff --git a/tests/conftest.py b/tests/conftest.py index 52c4c14e..d648bce8 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -17,13 +17,16 @@ import typing_extensions as te class TPEscape(te.Protocol): - def __call__(self, s: t.Any) -> Markup: ... + def __call__(self, s: t.Any) -> Markup: + ... class TPEscapeSilent(te.Protocol): - def __call__(self, s: t.Any | None) -> Markup: ... + def __call__(self, s: t.Any | None) -> Markup: + ... class TPSoftStr(te.Protocol): - def __call__(self, s: t.Any) -> str: ... + def __call__(self, s: t.Any) -> str: + ... @pytest.fixture( diff --git a/tests/test_markupsafe.py b/tests/test_markupsafe.py index 4df3209e..a2c361ec 100644 --- a/tests/test_markupsafe.py +++ b/tests/test_markupsafe.py @@ -205,6 +205,6 @@ def __html__(self) -> str: def test_soft_str(soft_str: TPSoftStr) -> None: - assert type(soft_str("")) is str - assert type(soft_str(Markup())) is Markup - assert type(soft_str(15)) is str + assert type(soft_str("")) is str # noqa: E721 + assert type(soft_str(Markup())) is Markup # noqa: E721 + assert type(soft_str(15)) is str # noqa: E721