Skip to content

Commit a026e6f

Browse files
committed
Update and apply linters
1 parent 03b0d29 commit a026e6f

13 files changed

Lines changed: 73 additions & 89 deletions

.pre-commit-config.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# See https://pre-commit.com for more information
22
# See https://pre-commit.com/hooks.html for more hooks
3+
ci:
4+
autoupdate_schedule: quarterly
35
repos:
46
- repo: https://github.com/pre-commit/pre-commit-hooks
57
rev: v4.6.0
@@ -15,7 +17,7 @@ repos:
1517
- id: fix-byte-order-marker
1618
- id: detect-private-key
1719
- repo: https://github.com/astral-sh/ruff-pre-commit
18-
rev: v0.3.5
20+
rev: v0.5.1
1921
hooks:
2022
- id: ruff
2123
args: [--fix, --exit-non-zero-on-fix]

conftest.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
# ruff: noqa: D100 D103 ANN401
2-
from typing import Any, Dict
2+
from __future__ import annotations
3+
4+
from typing import Any
35

46
import pytest
57

68
import tcod.ecs
79

810

911
@pytest.fixture(autouse=True)
10-
def _add_registry_entity(doctest_namespace: Dict[str, Any]) -> None:
12+
def _add_registry_entity(doctest_namespace: dict[str, Any]) -> None:
1113
"""Add registry and entity objects to all doctests."""
1214
registry = tcod.ecs.Registry()
1315
entity = registry["entity"]

docs/conf.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@
66

77
# -- Project information -----------------------------------------------------
88
# https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information
9+
from __future__ import annotations
10+
911
import importlib.metadata
1012

1113
project = "tcod-ecs"
12-
copyright = "2023-2024, Kyle Benesch"
14+
copyright = "2023-2024, Kyle Benesch" # noqa: A001
1315
author = "Kyle Benesch"
1416
release = importlib.metadata.version(project)
1517
version = ".".join(release.split(".")[:2])
@@ -32,7 +34,7 @@
3234
# https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output
3335

3436
html_theme = "furo"
35-
# html_static_path = ["_static"]
37+
# html_static_path = ["_static"] # noqa: ERA001
3638

3739

3840
intersphinx_mapping = {

pyproject.toml

Lines changed: 15 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -46,16 +46,6 @@ Changelog = "https://github.com/HexDecimal/python-tcod-ecs/blob/main/CHANGELOG.m
4646
Documentation = "https://python-tcod-ecs.readthedocs.io"
4747
Source = "https://github.com/HexDecimal/python-tcod-ecs"
4848

49-
[tool.black] # https://black.readthedocs.io/en/stable/usage_and_configuration/the_basics.html#configuration-via-a-file
50-
target-version = ["py38"]
51-
line-length = 120
52-
53-
[tool.isort] # https://pycqa.github.io/isort/docs/configuration/options.html
54-
py_version = "38"
55-
line_length = 120
56-
profile = "black"
57-
skip_gitignore = true
58-
5949
[tool.mypy] # https://mypy.readthedocs.io/en/stable/config_file.html
6050
files = "."
6151
exclude = ['^build/', '^\.']
@@ -86,44 +76,23 @@ testpaths = ["."]
8676
exclude_lines = ['^\s*\.\.\.', "if TYPE_CHECKING:", "# pragma: no cover"]
8777

8878
[tool.ruff]
89-
# https://beta.ruff.rs/docs/rules/
90-
select = [
91-
"C90", # mccabe
92-
"E", # pycodestyle
93-
"W", # pycodestyle
94-
"F", # Pyflakes
95-
"I", # isort
96-
"UP", # pyupgrade
97-
"YTT", # flake8-2020
98-
"ANN", # flake8-annotations
99-
"S", # flake8-bandit
100-
"B", # flake8-bugbear
101-
"C4", # flake8-comprehensions
102-
"DTZ", # flake8-datetimez
103-
"EM", # flake8-errmsg
104-
"EXE", # flake8-executable
105-
"RET", # flake8-return
106-
"ICN", # flake8-import-conventions
107-
"PIE", # flake8-pie
108-
"PT", # flake8-pytest-style
109-
"SIM", # flake8-simplify
110-
"PTH", # flake8-use-pathlib
111-
"PL", # Pylint
112-
"TRY", # tryceratops
113-
"RUF", # NumPy-specific rules
114-
"G", # flake8-logging-format
115-
"D", # pydocstyle
116-
]
79+
line-length = 120
80+
81+
[tool.ruff.lint] # https://docs.astral.sh/ruff/rules/
82+
select = ["ALL"]
11783
ignore = [
118-
"E501", # line-too-long
119-
"S101", # assert
12084
"ANN101", # missing-type-self
12185
"ANN102", # missing-type-cls
122-
"D206", # indent-with-spaces
123-
"W191", # tab-indentation
86+
"COM", # flake8-commas, handled by formatter
87+
"E501", # line-too-long
88+
"S101", # assert
89+
"SLF001", # private-member-access
90+
"T10", # flake8-debugger
91+
"T20", # flake8-print
12492
]
125-
line-length = 120
12693

127-
[tool.ruff.pydocstyle]
128-
# Use Google-style docstrings.
129-
convention = "google"
94+
[tool.ruff.lint.isort]
95+
required-imports = ["from __future__ import annotations"]
96+
97+
[tool.ruff.lint.pydocstyle]
98+
convention = "google" # Use Google-style docstrings.

tcod/ecs/_converter.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ def _is_defaultdict_type(type_hint: object) -> bool:
1212
return get_origin(type_hint) is defaultdict
1313

1414

15-
def _setup_defaultdict_factory(type_hint: type[defaultdict[Any, Any]] | type[object]) -> Callable[[], Any]:
15+
def _setup_defaultdict_factory(type_hint: type[defaultdict[Any, Any] | object]) -> Callable[[], Any]:
1616
"""Return the factory value for a defaultdict given its value type-hint."""
1717
assert type_hint is not Any
1818
if get_origin(type_hint) is not defaultdict:

tcod/ecs/callbacks.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,9 @@
66

77
from typing_extensions import TypeAlias
88

9-
from tcod.ecs.typing import ComponentKey
10-
119
if TYPE_CHECKING:
1210
from tcod.ecs.entity import Entity
11+
from tcod.ecs.typing import ComponentKey
1312

1413
_T = TypeVar("_T")
1514

tcod/ecs/constants.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
"""Special constants and sentinel values."""
22

3+
from __future__ import annotations
4+
35
from typing import Final
46

57
from sentinel_value import sentinel

tcod/ecs/entity.py

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
from __future__ import annotations
44

55
import warnings
6-
from collections.abc import Set
76
from typing import (
87
TYPE_CHECKING,
98
Any,
@@ -31,6 +30,8 @@
3130
from tcod.ecs.typing import ComponentKey
3231

3332
if TYPE_CHECKING:
33+
from collections.abc import Set as AbstractSet
34+
3435
from _typeshed import SupportsKeysAndGetItem
3536

3637
from tcod.ecs.registry import Registry
@@ -80,7 +81,7 @@ def world(self) -> Registry:
8081
warnings.warn("Use '.registry' instead of '.world'", DeprecationWarning, stacklevel=2)
8182
return self.registry
8283

83-
def __new__(cls, registry: Registry, uid: object = object) -> Entity:
84+
def __new__(cls, registry: Registry, uid: object = object) -> Entity: # noqa: PYI034
8485
"""Return a unique entity for the given `registry` and `uid`.
8586
8687
If an entity already exists with a matching `registry` and `uid` then that entity is returned.
@@ -334,7 +335,7 @@ def __repr__(self) -> str:
334335
>>> registry["foo"]
335336
<Entity(uid='foo')>
336337
"""
337-
uid_str = f"object at 0x{id(self.uid):X}" if self.uid.__class__ == object else repr(self.uid)
338+
uid_str = f"object at 0x{id(self.uid):X}" if self.uid.__class__ is object else repr(self.uid)
338339
items = [f"{self.__class__.__name__}(uid={uid_str})"]
339340
name = self.name
340341
if name is not None: # Switch to older style
@@ -426,7 +427,7 @@ def __getitem__(self, key: ComponentKey[T]) -> T:
426427
for entity in _traverse_entities(self.entity, self.traverse):
427428
try:
428429
return _components_by_entity[entity][key] # type: ignore[no-any-return]
429-
except KeyError:
430+
except KeyError: # noqa: PERF203
430431
pass
431432
raise KeyError(key)
432433

@@ -461,7 +462,7 @@ def __delitem__(self, key: type[object] | tuple[object, type[object]]) -> None:
461462
tcod.ecs.query._touch_component(self.entity.registry, key) # Component removed
462463
tcod.ecs.callbacks._on_component_changed(key, self.entity, old_value, None)
463464

464-
def keys(self) -> Set[ComponentKey[object]]: # type: ignore[override]
465+
def keys(self) -> AbstractSet[ComponentKey[object]]: # type: ignore[override]
465466
"""Return the components held by this entity, including inherited components."""
466467
_components_by_entity = self.entity.registry._components_by_entity
467468
if not self.traverse:
@@ -611,7 +612,7 @@ def __len__(self) -> int:
611612
"""Return the number of tags this entity has."""
612613
return len(self._as_set())
613614

614-
def __ior__(self, other: Set[object]) -> Self:
615+
def __ior__(self, other: AbstractSet[object]) -> Self:
615616
"""Add tags in-place.
616617
617618
.. versionadded:: 3.3
@@ -620,7 +621,7 @@ def __ior__(self, other: Set[object]) -> Self:
620621
self.add(to_add)
621622
return self
622623

623-
def __isub__(self, other: Set[Any]) -> Self:
624+
def __isub__(self, other: AbstractSet[Any]) -> Self:
624625
"""Remove tags in-place.
625626
626627
.. versionadded:: 3.3
@@ -787,10 +788,10 @@ def __delitem__(self, key: object) -> None:
787788
def __iter__(self) -> Iterator[Any]:
788789
"""Iterate over the unique relation tags of this entity."""
789790
_relation_tags_by_entity = self.entity.registry._relation_tags_by_entity
790-
EMPTY_DICT: dict[object, set[Entity]] = {}
791+
empty_dict: dict[object, set[Entity]] = {}
791792
yield from set().union(
792793
*(
793-
_relation_tags_by_entity.get(entity, EMPTY_DICT).keys()
794+
_relation_tags_by_entity.get(entity, empty_dict).keys()
794795
for entity in _traverse_entities(self.entity, self.traverse)
795796
)
796797
)
@@ -925,7 +926,7 @@ def __delitem__(self, target: Entity) -> None:
925926

926927
_relations_lookup_discard(registry, self.entity, self.key, target)
927928

928-
def keys(self) -> Set[Entity]: # type: ignore[override]
929+
def keys(self) -> AbstractSet[Entity]: # type: ignore[override]
929930
"""Return all entities with an associated component value."""
930931
_relation_components_by_entity = self.entity.registry._relation_components_by_entity
931932
result: set[Entity] = set()
@@ -1003,7 +1004,7 @@ def clear(self) -> None:
10031004
for component_key in list(self.entity.registry._relation_components_by_entity.get(self.entity, ())):
10041005
self[component_key].clear()
10051006

1006-
def keys(self) -> Set[ComponentKey[object]]: # type: ignore[override]
1007+
def keys(self) -> AbstractSet[ComponentKey[object]]: # type: ignore[override]
10071008
"""Returns the components keys this entity has relations for."""
10081009
_relation_components_by_entity = self.entity.registry._relation_components_by_entity
10091010
return set().union(

0 commit comments

Comments
 (0)