Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace Black with 'ruff format' #210

Merged
merged 2 commits into from
Nov 6, 2023
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
10 changes: 5 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,18 @@ jobs:
python: "3.12"
tox: py312
coverage: true
- name: "Lint: black"
python: "3.12"
tox: black
- name: "Lint: mypy"
python: "3.12"
tox: mypy
- name: "Lint: pyright"
python: "3.12"
tox: pyright
- name: "Lint: ruff"
- name: "Lint: ruff-format"
python: "3.12"
tox: ruff-format
- name: "Lint: ruff-lint"
python: "3.12"
tox: ruff
tox: ruff-lint
- name: "Docs"
python: "3.12"
tox: docs
Expand Down
9 changes: 2 additions & 7 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@ include = ["docs", "examples", "tests"]
python = "^3.8.0"
typing-extensions = { version = "^4.0.0", python = "<3.10" }

[tool.poetry.group.black.dependencies]
black = "^23.9.1"

[tool.poetry.group.dev.dependencies]
tox = "^4.11.3"

Expand All @@ -38,16 +35,13 @@ mypy = "^1.5.1"
pyright = "^1.1.327"

[tool.poetry.group.ruff.dependencies]
ruff = "^0.0.290"
ruff = "^0.1.4"

[tool.poetry.group.tests.dependencies]
pytest = "^7.4.2"
pytest-cov = "^4.1.0"
pytest-mock = "^3.11.1"

[tool.black]
target-version = ["py38", "py39", "py310", "py311", "py312"]

[tool.coverage.paths]
source = ["src"]

Expand Down Expand Up @@ -113,6 +107,7 @@ ignore = [
"ANN401", # any-type
"D203", # one-blank-line-before-class
"D213", # multi-line-summary-second-line
"ISC001", # single-line-implicit-string-concatenation
"PLR2004", # magic-value-comparison
"RET504", # unnecessary-assign
"TRY003", # raise-vanilla-args
Expand Down
2 changes: 1 addition & 1 deletion src/pykka/_actor.py
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ def _handle_failure(
"""Log unexpected failures, unregisters and stops the actor."""
logger.error(
f"Unhandled exception in {self}:",
exc_info=(exception_type, exception_value, traceback), # type: ignore[arg-type] # noqa: E501
exc_info=(exception_type, exception_value, traceback), # type: ignore[arg-type]
)
ActorRegistry.unregister(self.actor_ref)
self.actor_stopped.set()
Expand Down
6 changes: 3 additions & 3 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def events(runtime: Runtime) -> Events:

@pytest.fixture(scope="module")
def early_failing_actor_class(runtime: Runtime) -> type[Actor]:
class EarlyFailingActor(runtime.actor_class): # type: ignore[name-defined] # noqa: E501
class EarlyFailingActor(runtime.actor_class): # type: ignore[name-defined]
def __init__(self, events: Events) -> None:
super().__init__()
self.events = events
Expand All @@ -89,7 +89,7 @@ def on_start(self) -> None:

@pytest.fixture(scope="module")
def late_failing_actor_class(runtime: Runtime) -> type[Actor]:
class LateFailingActor(runtime.actor_class): # type: ignore[name-defined] # noqa: E501
class LateFailingActor(runtime.actor_class): # type: ignore[name-defined]
def __init__(self, events: Events) -> None:
super().__init__()
self.events = events
Expand All @@ -108,7 +108,7 @@ def on_stop(self) -> None:

@pytest.fixture(scope="module")
def failing_on_failure_actor_class(runtime: Runtime) -> type[Actor]:
class FailingOnFailureActor(runtime.actor_class): # type: ignore[name-defined] # noqa: E501
class FailingOnFailureActor(runtime.actor_class): # type: ignore[name-defined]
def __init__(self, events: Events) -> None:
super().__init__()
self.events = events
Expand Down
6 changes: 3 additions & 3 deletions tests/proxy/test_attribute_access.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def a_rw_property(self, value: str) -> None:

@pytest.fixture()
def actor_class(runtime: Runtime) -> type[PropertyActor]:
class PropertyActorImpl(PropertyActor, runtime.actor_class): # type: ignore[name-defined] # noqa: E501
class PropertyActorImpl(PropertyActor, runtime.actor_class): # type: ignore[name-defined]
pass

return PropertyActorImpl
Expand Down Expand Up @@ -67,7 +67,7 @@ def test_private_attr_access_raises_exception(
proxy: ActorProxy[PropertyActor],
) -> None:
with pytest.raises(AttributeError) as exc_info:
proxy._private_attr.get() # pyright: ignore[reportUnknownMemberType] # noqa: E501, SLF001
proxy._private_attr.get() # pyright: ignore[reportUnknownMemberType] # noqa: SLF001

assert "has no attribute '_private_attr'" in str(exc_info.value)

Expand Down Expand Up @@ -104,7 +104,7 @@ def test_read_only_property_cannot_be_set(


def test_property_is_not_accessed_when_creating_proxy(runtime: Runtime) -> None:
class ExpensiveSideEffectActor(runtime.actor_class): # type: ignore[name-defined] # noqa: E501
class ExpensiveSideEffectActor(runtime.actor_class): # type: ignore[name-defined]
@property
def a_property(self) -> NoReturn:
# Imagine code with side effects or heavy resource usage here
Expand Down
2 changes: 1 addition & 1 deletion tests/proxy/test_dynamic_method_calls.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def use_foo_through_self_proxy(self) -> Future[str]:

@pytest.fixture(scope="module")
def actor_class(runtime: Runtime) -> type[DynamicMethodActor]:
class DynamicMethodActorImpl(DynamicMethodActor, runtime.actor_class): # type: ignore[name-defined] # noqa: E501
class DynamicMethodActorImpl(DynamicMethodActor, runtime.actor_class): # type: ignore[name-defined]
pass

return DynamicMethodActorImpl
Expand Down
2 changes: 1 addition & 1 deletion tests/proxy/test_mocking.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def a_method(self) -> NoReturn:

@pytest.fixture()
def actor_class(runtime: Runtime) -> type[ActorForMocking]:
class ActorForMockingImpl(ActorForMocking, runtime.actor_class): # type: ignore[name-defined] # noqa: E501
class ActorForMockingImpl(ActorForMocking, runtime.actor_class): # type: ignore[name-defined]
pass

return ActorForMockingImpl
Expand Down
4 changes: 2 additions & 2 deletions tests/proxy/test_proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def a_method(self) -> None:

@pytest.fixture(scope="module")
def actor_class(runtime: Runtime) -> type[ActorForProxying]:
class ActorForProxyingImpl(ActorForProxying, runtime.actor_class): # type: ignore[name-defined] # noqa: E501
class ActorForProxyingImpl(ActorForProxying, runtime.actor_class): # type: ignore[name-defined]
pass

return ActorForProxyingImpl
Expand Down Expand Up @@ -153,7 +153,7 @@ def test_actor_proxy_does_not_expose_proxy_to_self(
runtime: Runtime,
log_handler: PykkaTestLogHandler,
) -> None:
class SelfReferencingActor(runtime.actor_class): # type: ignore[name-defined] # noqa: E501
class SelfReferencingActor(runtime.actor_class): # type: ignore[name-defined]
def __init__(self) -> None:
super().__init__()
self.self_proxy = self.actor_ref.proxy()
Expand Down
4 changes: 2 additions & 2 deletions tests/proxy/test_static_method_calls.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@ def raise_exception(self) -> NoReturn:
raise Exception("boom!")

def talk_with_self(self) -> Future[str]:
return self.actor_ref.proxy().functional_hello("from the future") # type: ignore[no-any-return] # noqa: E501
return self.actor_ref.proxy().functional_hello("from the future") # type: ignore[no-any-return]


@pytest.fixture(scope="module")
def actor_class(runtime: Runtime) -> type[StaticMethodActor]:
class StaticMethodActorImpl(StaticMethodActor, runtime.actor_class): # type: ignore[name-defined] # noqa: E501
class StaticMethodActorImpl(StaticMethodActor, runtime.actor_class): # type: ignore[name-defined]
pass

return StaticMethodActorImpl
Expand Down
2 changes: 1 addition & 1 deletion tests/proxy/test_traversable.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def nested_object_property(self) -> NestedWithAttrMarker:

@pytest.fixture()
def actor_class(runtime: Runtime) -> type[Actor]:
class TraversableObjectsActorImpl(TraversableObjectsActor, runtime.actor_class): # type: ignore[name-defined] # noqa: E501
class TraversableObjectsActorImpl(TraversableObjectsActor, runtime.actor_class): # type: ignore[name-defined]
pass

return TraversableObjectsActorImpl
Expand Down
2 changes: 1 addition & 1 deletion tests/proxy/test_typed_proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class FooProxy(ActorMemberMixin, ActorProxy[CircleActor]):

@pytest.fixture(scope="module")
def actor_class(runtime: Runtime) -> type[CircleActor]:
class FooActorImpl(CircleActor, runtime.actor_class): # type: ignore[name-defined] # noqa: E501
class FooActorImpl(CircleActor, runtime.actor_class): # type: ignore[name-defined]
pass

return FooActorImpl
Expand Down
4 changes: 2 additions & 2 deletions tests/test_actor.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def on_stop(self) -> None:

@pytest.fixture(scope="module")
def actor_class(runtime: Runtime) -> type[AnActor]:
class ActorAImpl(AnActor, runtime.actor_class): # type: ignore[name-defined] # noqa: E501
class ActorAImpl(AnActor, runtime.actor_class): # type: ignore[name-defined]
pass

return ActorAImpl
Expand All @@ -83,7 +83,7 @@ def actor_ref(

@pytest.fixture(scope="module")
def early_stopping_actor_class(runtime: Runtime) -> type[EarlyStoppingActor]:
class EarlyStoppingActorImpl(EarlyStoppingActor, runtime.actor_class): # type: ignore[name-defined] # noqa: E501
class EarlyStoppingActorImpl(EarlyStoppingActor, runtime.actor_class): # type: ignore[name-defined]
pass

return EarlyStoppingActorImpl
Expand Down
2 changes: 1 addition & 1 deletion tests/test_logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def raise_exception(self) -> NoReturn:

@pytest.fixture(scope="module")
def actor_class(runtime: Runtime) -> type[LoggingActor]:
class LoggingActorImpl(LoggingActor, runtime.actor_class): # type: ignore[name-defined] # noqa: E501
class LoggingActorImpl(LoggingActor, runtime.actor_class): # type: ignore[name-defined]
pass

return LoggingActorImpl
Expand Down
2 changes: 1 addition & 1 deletion tests/test_ref.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def on_receive(self, message: str) -> Any:

@pytest.fixture(scope="module")
def actor_class(runtime: Runtime) -> type[ReferencableActor]:
class ReferencableActorImpl(ReferencableActor, runtime.actor_class): # type: ignore[name-defined] # noqa: E501
class ReferencableActorImpl(ReferencableActor, runtime.actor_class): # type: ignore[name-defined]
pass

return ReferencableActorImpl
Expand Down
18 changes: 6 additions & 12 deletions tests/test_registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,15 @@ class ActorB(ActorBase):

@pytest.fixture(scope="module")
def actor_a_class(runtime: Runtime) -> type[ActorA]:
class ActorAImpl(ActorA, runtime.actor_class): # type: ignore[name-defined] # noqa: E501
class ActorAImpl(ActorA, runtime.actor_class): # type: ignore[name-defined]
pass

return ActorAImpl


@pytest.fixture(scope="module")
def actor_b_class(runtime: Runtime) -> type[ActorB]:
class ActorBImpl(ActorB, runtime.actor_class): # type: ignore[name-defined] # noqa: E501
class ActorBImpl(ActorB, runtime.actor_class): # type: ignore[name-defined]
pass

return ActorBImpl
Expand Down Expand Up @@ -123,22 +123,16 @@ def test_stop_all_stops_last_started_actor_first_if_blocking(

stopped_actors = []
started_actors = [mocker.Mock(name=f"{i}") for i in range(3)]
started_actors[
0
].stop.side_effect = lambda *a, **kw: stopped_actors.append( # pyright: ignore[reportUnknownLambdaType, reportUnknownMemberType] # noqa: E501
started_actors[0].stop.side_effect = lambda *a, **kw: stopped_actors.append( # pyright: ignore[reportUnknownLambdaType, reportUnknownMemberType]
started_actors[0]
)
started_actors[
1
].stop.side_effect = lambda *a, **kw: stopped_actors.append( # pyright: ignore[reportUnknownLambdaType, reportUnknownMemberType] # noqa: E501
started_actors[1].stop.side_effect = lambda *a, **kw: stopped_actors.append( # pyright: ignore[reportUnknownLambdaType, reportUnknownMemberType]
started_actors[1]
)
started_actors[
2
].stop.side_effect = lambda *a, **kw: stopped_actors.append( # pyright: ignore[reportUnknownLambdaType, reportUnknownMemberType] # noqa: E501
started_actors[2].stop.side_effect = lambda *a, **kw: stopped_actors.append( # pyright: ignore[reportUnknownLambdaType, reportUnknownMemberType]
started_actors[2]
)
ActorRegistry.get_all.return_value = ( # type: ignore[attr-defined] # pyright: ignore[reportFunctionMemberAccess] # noqa: E501
ActorRegistry.get_all.return_value = ( # type: ignore[attr-defined] # pyright: ignore[reportFunctionMemberAccess]
started_actors
)

Expand Down
14 changes: 7 additions & 7 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tox]
isolated_build = true
envlist = py38, py39, py310, py311, py312, black, docs, mypy, ruff
envlist = py38, py39, py310, py311, py312, docs, mypy, ruff-format, ruff-lint

[testenv]
allowlist_externals = poetry
Expand All @@ -11,11 +11,6 @@ commands =
--cov=pykka --cov-report=term-missing \
{posargs}

[testenv:black]
commands =
poetry install --only=black
poetry run black .

[testenv:docs]
commands =
poetry install --all-extras --only=main,docs
Expand All @@ -31,7 +26,12 @@ commands =
poetry install --only=main,dev,docs,tests,pyright
poetry run pyright src tests

[testenv:ruff]
[testenv:ruff-format]
commands =
poetry install --only=ruff
poetry run ruff format .

[testenv:ruff-lint]
commands =
poetry install --only=ruff
poetry run ruff .