Skip to content

Commit

Permalink
Replace black with ruff formatter (#2330)
Browse files Browse the repository at this point in the history
  • Loading branch information
aminalaee committed Nov 8, 2023
1 parent 2c066af commit 93494a4
Show file tree
Hide file tree
Showing 8 changed files with 15 additions and 13 deletions.
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ Source = "https://github.com/encode/starlette"
[tool.hatch.version]
path = "starlette/__init__.py"

[tool.ruff]
[tool.ruff.lint]
select = ["E", "F", "I"]

[tool.ruff.isort]
[tool.ruff.lint.isort]
combine-as-imports = true

[tool.mypy]
Expand Down
3 changes: 1 addition & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@
-e .[full]

# Testing
black==23.10.1
coverage==7.3.1
importlib-metadata==6.8.0
mypy==1.5.1
ruff==0.1.3
ruff==0.1.4
typing_extensions==4.8.0
types-contextvars==2.4.7.3
types-PyYAML==6.0.12.12
Expand Down
2 changes: 1 addition & 1 deletion scripts/check
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export SOURCE_FILES="starlette tests"
set -x

./scripts/sync-version
${PREFIX}black --check --diff $SOURCE_FILES
${PREFIX}ruff format --check --diff $SOURCE_FILES
# TODO: Use `[[tool.mypy.overrides]]` on the `pyproject.toml` when the mypy issue is solved:
# github.com/python/mypy/issues/10045. Check github.com/encode/starlette/pull/2180 for more info.
${PREFIX}mypy starlette
Expand Down
2 changes: 1 addition & 1 deletion scripts/lint
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ export SOURCE_FILES="starlette tests"

set -x

${PREFIX}black $SOURCE_FILES
${PREFIX}ruff format $SOURCE_FILES
${PREFIX}ruff --fix $SOURCE_FILES
8 changes: 4 additions & 4 deletions starlette/applications.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,9 @@ def add_exception_handler(
self.exception_handlers[exc_class_or_status_code] = handler

def add_event_handler(
self, event_type: str, func: typing.Callable # type: ignore[type-arg]
self,
event_type: str,
func: typing.Callable, # type: ignore[type-arg]
) -> None: # pragma: no cover
self.router.add_event_handler(event_type, func)

Expand Down Expand Up @@ -208,9 +210,7 @@ def decorator(func: typing.Callable) -> typing.Callable: # type: ignore[type-ar

return decorator

def websocket_route(
self, path: str, name: str | None = None
) -> typing.Callable: # type: ignore[type-arg]
def websocket_route(self, path: str, name: str | None = None) -> typing.Callable: # type: ignore[type-arg]
"""
We no longer document this decorator style API, and its usage is discouraged.
Instead you should use the following approach:
Expand Down
2 changes: 1 addition & 1 deletion starlette/middleware/authentication.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def __init__(
self.backend = backend
self.on_error: typing.Callable[
[HTTPConnection, AuthenticationError], Response
] = (on_error if on_error is not None else self.default_on_error)
] = on_error if on_error is not None else self.default_on_error

async def __call__(self, scope: Scope, receive: Receive, send: Send) -> None:
if scope["type"] not in ["http", "websocket"]:
Expand Down
5 changes: 4 additions & 1 deletion starlette/middleware/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,10 @@ def format_line(
def generate_frame_html(self, frame: inspect.FrameInfo, is_collapsed: bool) -> str:
code_context = "".join(
self.format_line(
index, line, frame.lineno, frame.index # type: ignore[arg-type]
index,
line,
frame.lineno,
frame.index, # type: ignore[arg-type]
)
for index, line in enumerate(frame.code_context or [])
)
Expand Down
2 changes: 1 addition & 1 deletion starlette/routing.py
Original file line number Diff line number Diff line change
Expand Up @@ -565,7 +565,7 @@ async def __aexit__(
def _wrap_gen_lifespan_context(
lifespan_context: typing.Callable[
[typing.Any], typing.Generator[typing.Any, typing.Any, typing.Any]
]
],
) -> typing.Callable[[typing.Any], typing.AsyncContextManager[typing.Any]]:
cmgr = contextlib.contextmanager(lifespan_context)

Expand Down

0 comments on commit 93494a4

Please sign in to comment.