Skip to content

Commit

Permalink
use ruff for linting and formatting (#425)
Browse files Browse the repository at this point in the history
  • Loading branch information
davidism authored Feb 2, 2024
2 parents 872a117 + 8169529 commit b3b0f02
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 61 deletions.
22 changes: 0 additions & 22 deletions .flake8

This file was deleted.

10 changes: 3 additions & 7 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -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/
26 changes: 6 additions & 20 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -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
22 changes: 22 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
14 changes: 8 additions & 6 deletions src/markupsafe/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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)
Expand Down
9 changes: 6 additions & 3 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
6 changes: 3 additions & 3 deletions tests/test_markupsafe.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit b3b0f02

Please sign in to comment.