Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Switch to ruff instead of flake8. #14633

Merged
merged 6 commits into from
Dec 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 0 additions & 18 deletions .flake8

This file was deleted.

2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ jobs:
- run: scripts-dev/check_schema_delta.py --force-colors

lint:
uses: "matrix-org/backend-meta/.github/workflows/python-poetry-ci.yml@v1"
uses: "matrix-org/backend-meta/.github/workflows/python-poetry-ci.yml@v2"
with:
typechecking-extras: "all"

Expand Down
1 change: 1 addition & 0 deletions changelog.d/14633.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Use [ruff](https://github.com/charliermarsh/ruff/) instead of flake8.
119 changes: 29 additions & 90 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

46 changes: 42 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,46 @@ target-version = ['py37', 'py38', 'py39', 'py310']
# https://black.readthedocs.io/en/stable/usage_and_configuration/file_collection_and_discovery.html#gitignore
# Use `extend-exclude` if you want to exclude something in addition to this.

[tool.ruff]
line-length = 88

# See https://github.com/charliermarsh/ruff/#pycodestyle
# for error codes. The ones we ignore are:
# E731: do not assign a lambda expression, use a def
# E501: Line too long (black enforces this for us)
#
# See https://github.com/charliermarsh/ruff/#pyflakes
# F401: unused import
# F811: Redefinition of unused
# F821: Undefined name
#
# flake8-bugbear compatible checks. Its error codes are described at
# https://github.com/charliermarsh/ruff/#flake8-bugbear
# B019: Use of functools.lru_cache or functools.cache on methods can lead to memory leaks
# B023: Functions defined inside a loop must not use variables redefined in the loop
# B024: Abstract base class with no abstract method.
ignore = [
"B019",
"B023",
"B024",
"E501",
"E731",
"F401",
"F811",
"F821",
]
select = [
# pycodestyle checks.
"E",
"W",
# pyflakes checks.
"F",
# flake8-bugbear checks.
"B0",
# flake8-comprehensions checks.
"C4",
]

[tool.isort]
line_length = 88
sections = ["FUTURE", "STDLIB", "THIRDPARTY", "TWISTED", "FIRSTPARTY", "TESTS", "LOCALFOLDER"]
Expand Down Expand Up @@ -274,12 +314,10 @@ all = [
]

[tool.poetry.dev-dependencies]
## We pin black so that our tests don't start failing on new releases.
# We pin black so that our tests don't start failing on new releases.
isort = ">=5.10.1"
black = ">=22.3.0"
flake8-comprehensions = "*"
flake8-bugbear = ">=21.3.2"
flake8 = "*"
ruff = "0.0.189"

# Typechecking
mypy = "*"
Expand Down
5 changes: 2 additions & 3 deletions scripts-dev/lint.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
#!/usr/bin/env bash
#
# Runs linting scripts over the local Synapse checkout
# isort - sorts import statements
# black - opinionated code formatter
# flake8 - lints and finds mistakes
# ruff - lints and finds mistakes

set -e

Expand Down Expand Up @@ -105,6 +104,6 @@ set -x
isort "${files[@]}"
python3 -m black "${files[@]}"
./scripts-dev/config-lint.sh
flake8 "${files[@]}"
ruff "${files[@]}"
./scripts-dev/check_pydantic_models.py lint
mypy
2 changes: 2 additions & 0 deletions stubs/frozendict.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

# Stub for frozendict.

from __future__ import annotations
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We do seem to actually need these, I'm not sure why flake8 was running OK without them. Maybe it wasn't even checking *.pyi files?


from typing import Any, Hashable, Iterable, Iterator, Mapping, Tuple, TypeVar, overload

_KT = TypeVar("_KT", bound=Hashable) # Key type.
Expand Down
2 changes: 2 additions & 0 deletions stubs/icu.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

# Stub for PyICU.

from __future__ import annotations

class Locale:
@staticmethod
def getDefault() -> Locale: ...
Expand Down
2 changes: 2 additions & 0 deletions stubs/sortedcontainers/sorteddict.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
# https://github.com/grantjenks/python-sortedcontainers/blob/eea42df1f7bad2792e8da77335ff888f04b9e5ae/sortedcontainers/sorteddict.pyi
# (from https://github.com/grantjenks/python-sortedcontainers/pull/107)

from __future__ import annotations

from typing import (
Any,
Callable,
Expand Down
2 changes: 2 additions & 0 deletions stubs/sortedcontainers/sortedlist.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
# https://github.com/grantjenks/python-sortedcontainers/blob/a419ffbd2b1c935b09f11f0971696e537fd0c510/sortedcontainers/sortedlist.pyi
# (from https://github.com/grantjenks/python-sortedcontainers/pull/107)

from __future__ import annotations

from typing import (
Any,
Callable,
Expand Down
2 changes: 2 additions & 0 deletions stubs/sortedcontainers/sortedset.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
# https://github.com/grantjenks/python-sortedcontainers/blob/d0a225d7fd0fb4c54532b8798af3cbeebf97e2d5/sortedcontainers/sortedset.pyi
# (from https://github.com/grantjenks/python-sortedcontainers/pull/107)

from __future__ import annotations

from typing import (
AbstractSet,
Any,
Expand Down
2 changes: 2 additions & 0 deletions synapse/config/_base.pyi
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import argparse
from typing import (
Any,
Expand Down