Skip to content

Commit

Permalink
Merge pull request #65 from ikalnytskyi/chore/ruff-rules
Browse files Browse the repository at this point in the history
More Ruff lint rules
  • Loading branch information
ikalnytskyi authored Nov 18, 2023
2 parents 0f30d1c + eaedeaf commit 00972d0
Show file tree
Hide file tree
Showing 8 changed files with 85 additions and 62 deletions.
37 changes: 30 additions & 7 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ description = "Dependency injection framework designed with Python in mind."
readme = "README.rst"
requires-python = ">=3.8"
license = "MIT"
authors = [
{ name = "Ihor Kalnytskyi", email = "[email protected]" },
]
authors = [{ name = "Ihor Kalnytskyi", email = "[email protected]" }]
classifiers = [
"Intended Audience :: Developers",
"License :: OSI Approved :: MIT License",
Expand Down Expand Up @@ -38,7 +36,7 @@ source = "vcs"

[tool.hatch.envs.test]
dependencies = ["pytest", "flask"]
scripts.run = "python -m pytest --strict {args:-vv}"
scripts.run = "python -m pytest --strict-markers {args:-vv}"

[tool.hatch.envs.lint]
detached = true
Expand All @@ -50,11 +48,36 @@ dependencies = ["sphinx", "sphinx_rtd_theme"]
scripts.run = "sphinx-build -W -b html docs docs/_build/"

[tool.ruff]
select = ["F", "E", "W", "I", "S", "FBT", "B", "C4", "DTZ", "T10", "ISC", "RET", "SLF", "RUF"]
ignore = ["S101", "B904", "ISC001"]
select = [
"F",
"E",
"W",
"I",
"D",
"UP",
"S",
"FBT",
"B",
"C4",
"DTZ",
"T10",
"ISC",
"PIE",
"T20",
"PYI",
"PT",
"RET",
"SLF",
"SIM",
"TCH",
"ERA",
"RUF",
]
ignore = ["D203", "D213", "D401", "S101", "B904", "ISC001", "PT011", "SIM117"]

[tool.ruff.isort]
known-first-party = ["picobox"]

[tool.ruff.per-file-ignores]
"examples/*" = ["I"]
"examples/*" = ["I", "D", "T20"]
"tests/*" = ["D"]
2 changes: 1 addition & 1 deletion src/picobox/_box.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ def get(self, key: t.Hashable, default: t.Any = _unset) -> t.Any:

return value

def pass_(self, key: t.Hashable, *, as_: t.Text = _unset):
def pass_(self, key: t.Hashable, *, as_: str = _unset):
r"""Pass a dependency to a function if nothing explicitly passed.
The decorator implements late binding which means it does not require
Expand Down
2 changes: 1 addition & 1 deletion src/picobox/_stack.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def do(magic):
.. versionadded:: 2.2
"""

def __init__(self, name: t.Optional[t.Text] = None):
def __init__(self, name: t.Optional[str] = None):
self._name = name
self._stack = []
self._lock = threading.Lock()
Expand Down
8 changes: 3 additions & 5 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@


@pytest.fixture(
scope="function",
params=[
42,
"42",
Expand All @@ -22,7 +21,6 @@ def hashable_value(request):


@pytest.fixture(
scope="function",
params=[
42,
"42",
Expand All @@ -41,16 +39,16 @@ def any_value(request):
return request.param


@pytest.fixture(scope="function")
@pytest.fixture()
def supported_key(hashable_value):
return hashable_value


@pytest.fixture(scope="function")
@pytest.fixture()
def supported_value(any_value):
return any_value


@pytest.fixture(params=[picobox.Box, picobox.ChainBox])
def boxclass(request):
yield request.param
return request.param
22 changes: 11 additions & 11 deletions tests/contrib/test_flaskscopes.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,33 +6,33 @@
from picobox.contrib import flaskscopes


@pytest.fixture(scope="function")
@pytest.fixture()
def appscope():
return flaskscopes.application()


@pytest.fixture(scope="function")
@pytest.fixture()
def reqscope():
return flaskscopes.request()


@pytest.fixture(scope="function")
@pytest.fixture()
def flaskapp():
return flask.Flask("test")


@pytest.fixture(scope="function")
@pytest.fixture()
def appcontext(flaskapp):
return flaskapp.app_context


@pytest.fixture(scope="function")
@pytest.fixture()
def reqcontext(flaskapp):
return flaskapp.test_request_context


@pytest.mark.parametrize(
"scopename, ctx",
("scopename", "ctx"),
[
("appscope", "appcontext"),
("reqscope", "reqcontext"),
Expand Down Expand Up @@ -63,7 +63,7 @@ def test_scope_set_nocontext(request, scopename):


@pytest.mark.parametrize(
"scopename, ctx",
("scopename", "ctx"),
[
("appscope", "appcontext"),
("reqscope", "reqcontext"),
Expand All @@ -83,7 +83,7 @@ def test_scope_set_value_overwrite(request, scopename, ctx):


@pytest.mark.parametrize(
"scopename, ctx",
("scopename", "ctx"),
[
("appscope", "appcontext"),
("reqscope", "reqcontext"),
Expand All @@ -99,7 +99,7 @@ def test_scope_get_keyerror(request, scopename, ctx, supported_key):


@pytest.mark.parametrize(
"scopename, ctx",
("scopename", "ctx"),
[
("appscope", "appcontext"),
("reqscope", "reqcontext"),
Expand Down Expand Up @@ -129,7 +129,7 @@ def test_scope_state_not_leaked(request, scopename, ctx):


@pytest.mark.parametrize(
"scopename, ctx",
("scopename", "ctx"),
[
("appscope", "appcontext"),
],
Expand All @@ -147,7 +147,7 @@ def test_scope_value_shared(request, scopename, ctx):


@pytest.mark.parametrize(
"scopename, ctx",
("scopename", "ctx"),
[
("reqscope", "reqcontext"),
],
Expand Down
22 changes: 11 additions & 11 deletions tests/test_box.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ def test_box_get_default(boxclass):


@pytest.mark.parametrize(
"args, kwargs, rv",
("args", "kwargs", "rv"),
[
((1, 2, 3), {}, 6),
((1, 2), {"c": 3}, 6),
Expand All @@ -148,7 +148,7 @@ def fn(a, b, c):


@pytest.mark.parametrize(
"args, kwargs, rv",
("args", "kwargs", "rv"),
[
((1, 2, 3), {}, 6),
((1, 2), {"c": 3}, 6),
Expand All @@ -170,7 +170,7 @@ def fn(a, b, c):


@pytest.mark.parametrize(
"args, kwargs, rv",
("args", "kwargs", "rv"),
[
((1, 2, 3), {}, 6),
((1, 2), {"c": 3}, 6),
Expand All @@ -193,7 +193,7 @@ def fn(a, b, c):


@pytest.mark.parametrize(
"args, kwargs, rv",
("args", "kwargs", "rv"),
[
((1, 2, 3), {}, 6),
((1, 2), {"c": 3}, 6),
Expand All @@ -216,7 +216,7 @@ def fn(a, b, c=20):


@pytest.mark.parametrize(
"args, kwargs, rv",
("args", "kwargs", "rv"),
[
((1, 2, 3), {}, 6),
((1, 2), {"c": 3}, 6),
Expand All @@ -242,7 +242,7 @@ def fn(a, b, c):


@pytest.mark.parametrize(
"args, kwargs, rv",
("args", "kwargs", "rv"),
[
((1, 2, 3), {}, 6),
((1, 2), {"c": 3}, 6),
Expand Down Expand Up @@ -271,7 +271,7 @@ def fn(a, b, c):


@pytest.mark.parametrize(
"args, kwargs, rv",
("args", "kwargs", "rv"),
[
((1, 2, 3), {}, 6),
((1, 2), {"c": 3}, 6),
Expand All @@ -298,7 +298,7 @@ def fn(a, b, c):


@pytest.mark.parametrize(
"args, kwargs, rv",
("args", "kwargs", "rv"),
[
((1, 2, 3), {}, 6),
((1, 2), {"c": 3}, 6),
Expand Down Expand Up @@ -330,7 +330,7 @@ def fn(a, b, c):


@pytest.mark.parametrize(
"args, kwargs, rv",
("args", "kwargs", "rv"),
[
((1, 2, 3), {}, 6),
((1, 2), {"c": 3}, 6),
Expand All @@ -352,7 +352,7 @@ def fn(a, b, c):


@pytest.mark.parametrize(
"args, kwargs, rv",
("args", "kwargs", "rv"),
[
((1,), {}, 1),
((), {"x": 1}, 1),
Expand All @@ -372,7 +372,7 @@ def __init__(self, x):


@pytest.mark.parametrize(
"args, kwargs, rv",
("args", "kwargs", "rv"),
[
((0,), {}, 41),
((), {"x": 0}, 41),
Expand Down
Loading

0 comments on commit 00972d0

Please sign in to comment.