Skip to content

Commit 6515955

Browse files
committed
remove unused ignores.
1 parent 8fead8a commit 6515955

22 files changed

Lines changed: 90 additions & 86 deletions

pyproject.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ test = [
7575
"syrupy>=4.5.0",
7676
"aiohttp>=3.11.0", # For HTTPPath tests.
7777
]
78-
typing = ["ty>=0.0.5"]
78+
typing = ["ty>=0.0.7"]
7979

8080
[project.urls]
8181
Changelog = "https://pytask-dev.readthedocs.io/en/stable/changes.html"
@@ -166,6 +166,9 @@ filterwarnings = [
166166
"ignore:The --rsyncdir command line argument:DeprecationWarning",
167167
]
168168

169+
[tool.ty.rules]
170+
unused-ignore-comment = "error"
171+
169172
[tool.ty.src]
170173
exclude = ["src/_pytask/_hashlib.py"]
171174

src/_pytask/cache.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,21 @@
1919

2020
if TYPE_CHECKING:
2121
from collections.abc import Callable
22+
from typing import TypeAlias
23+
24+
from ty_extensions import Intersection
25+
26+
Memoized: TypeAlias = "Intersection[Callable[P, R], HasCache]"
2227

2328
P = ParamSpec("P")
2429
R = TypeVar("R")
2530

2631

27-
class MemoizedCallable(Protocol[P, R]):
28-
"""A callable that has been memoized and has a cache attribute."""
32+
class HasCache(Protocol):
33+
"""Protocol for objects that have a cache attribute."""
2934

3035
cache: Cache
3136

32-
def __call__(self, *args: P.args, **kwargs: P.kwargs) -> R:
33-
"""Call the memoized function."""
34-
...
35-
3637

3738
@define
3839
class CacheInfo:
@@ -46,7 +47,7 @@ class Cache:
4647
_sentinel: Any = field(factory=object)
4748
cache_info: CacheInfo = field(factory=CacheInfo)
4849

49-
def memoize(self, func: Callable[P, R]) -> MemoizedCallable[P, R]:
50+
def memoize(self, func: Callable[P, R]) -> Memoized[P, R]:
5051
func_module = getattr(func, "__module__", "")
5152
func_name = getattr(func, "__name__", "")
5253
prefix = f"{func_module}.{func_name}:"
@@ -68,9 +69,9 @@ def wrapped(*args: P.args, **kwargs: P.kwargs) -> R:
6869

6970
return value
7071

71-
wrapped.cache = self # type: ignore[attr-defined]
72+
wrapped.cache = self # ty: ignore[unresolved-attribute]
7273

73-
return wrapped # type: ignore[return-value]
74+
return wrapped
7475

7576
def add(self, key: str, value: Any) -> None:
7677
self._cache[key] = value

src/_pytask/click.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,10 @@
3737
if importlib.metadata.version("click") < "8.2":
3838
from click.parser import split_opt
3939
else:
40-
from click.parser import ( # type: ignore[attr-defined, no-redef, unused-ignore, unresolved-import]
41-
_split_opt as split_opt, # ty: ignore[unresolved-import]
42-
)
40+
from click.parser import _split_opt as split_opt # ty: ignore[unresolved-import]
4341

4442

45-
class EnumChoice(Choice): # type: ignore[type-arg, unused-ignore]
43+
class EnumChoice(Choice):
4644
"""An enum-based choice type.
4745
4846
The implementation is copied from https://github.com/pallets/click/pull/2210 and
@@ -75,7 +73,7 @@ def convert(self, value: Any, param: Parameter | None, ctx: Context | None) -> A
7573
class _OptionHighlighter(RegexHighlighter):
7674
"""A highlighter for help texts."""
7775

78-
highlights: ClassVar = [ # type: ignore[misc]
76+
highlights: ClassVar = [
7977
r"(?P<switch>\-\w)\b",
8078
r"(?P<option>\-\-[\w\-]+)",
8179
r"\-\-[\w\-]+(?P<metavar>[ |=][\w\.:]+)",
@@ -329,7 +327,7 @@ def _format_help_text( # noqa: C901, PLR0912, PLR0915
329327
elif param.is_bool_flag and param.secondary_opts: # type: ignore[attr-defined]
330328
# For boolean flags that have distinct True/False opts,
331329
# use the opt without prefix instead of the value.
332-
default_string = split_opt( # type: ignore[operator, unused-ignore]
330+
default_string = split_opt(
333331
(param.opts if param.default else param.secondary_opts)[0]
334332
)[1]
335333
elif (

src/_pytask/coiled_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
except ImportError:
1414

1515
@define
16-
class Function: # type: ignore[no-redef]
16+
class Function:
1717
cluster_kwargs: dict[str, Any]
1818
environ: dict[str, Any]
1919
function: Callable[..., Any] | None

src/_pytask/collect.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ def _collect_from_tasks(session: Session) -> None:
120120
raw_task = task_decorator()(raw_task) # noqa: PLW2901
121121

122122
path = get_file(raw_task)
123-
name = raw_task.pytask_meta.name # ty: ignore[possibly-missing-attribute]
123+
name = raw_task.pytask_meta.name
124124

125125
if has_mark(raw_task, "task"):
126126
# When tasks with @task are passed to the programmatic interface

src/_pytask/collect_command.py

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -124,15 +124,11 @@ def _find_common_ancestor_of_all_nodes(
124124
for task in tasks:
125125
all_paths.append(task.path)
126126
if show_nodes:
127-
all_paths.extend( # type: ignore[var-annotated]
128-
x.path
129-
for x in tree_leaves(task.depends_on) # type: ignore[arg-type]
130-
if isinstance(x, PPathNode)
127+
all_paths.extend(
128+
x.path for x in tree_leaves(task.depends_on) if isinstance(x, PPathNode)
131129
)
132-
all_paths.extend( # type: ignore[var-annotated]
133-
x.path
134-
for x in tree_leaves(task.produces) # type: ignore[arg-type]
135-
if isinstance(x, PPathNode)
130+
all_paths.extend(
131+
x.path for x in tree_leaves(task.produces) if isinstance(x, PPathNode)
136132
)
137133

138134
return find_common_ancestor(*all_paths, *paths)
@@ -200,7 +196,7 @@ def _print_collected_tasks(
200196
)
201197

202198
if show_nodes:
203-
deps: list[Any] = list(tree_leaves(task.depends_on)) # type: ignore[arg-type]
199+
deps: list[Any] = list(tree_leaves(task.depends_on))
204200
for node in sorted(
205201
deps,
206202
key=(
@@ -212,7 +208,7 @@ def _print_collected_tasks(
212208
text = format_node_name(node, (common_ancestor,))
213209
task_branch.add(Text.assemble(FILE_ICON, "<Dependency ", text, ">"))
214210

215-
products: list[Any] = list(tree_leaves(task.produces)) # type: ignore[arg-type]
211+
products: list[Any] = list(tree_leaves(task.produces))
216212
for node in sorted(
217213
products,
218214
key=lambda x: x.path.as_posix()

src/_pytask/collect_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ def parse_dependencies_from_task_function(
112112
)
113113
dependencies[parameter_name] = PythonNode(value=value, name=node_name)
114114
else:
115-
dependencies[parameter_name] = nodes # type: ignore[assignment]
115+
dependencies[parameter_name] = nodes
116116
return dependencies
117117

118118

src/_pytask/dag.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,8 @@ def _add_product(
8888
for task in tasks:
8989
dag.add_node(task.signature, task=task)
9090

91-
tree_map(lambda x: _add_dependency(dag, task, x), task.depends_on) # type: ignore[arg-type]
92-
tree_map(lambda x: _add_product(dag, task, x), task.produces) # type: ignore[arg-type]
91+
tree_map(lambda x: _add_dependency(dag, task, x), task.depends_on)
92+
tree_map(lambda x: _add_product(dag, task, x), task.produces)
9393

9494
# If a node is a PythonNode wrapped in another PythonNode, it is a product from
9595
# another task that is a dependency in the current task. Thus, draw an edge
@@ -98,7 +98,7 @@ def _add_product(
9898
lambda x: dag.add_edge(x.value.signature, x.signature)
9999
if isinstance(x, PythonNode) and isinstance(x.value, PythonNode)
100100
else None,
101-
task.depends_on, # type: ignore[arg-type]
101+
task.depends_on,
102102
)
103103
return dag
104104

src/_pytask/data_catalog.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ def add(self, name: str, node: PNode | PProvisionalNode | Any = None) -> None:
121121
name=name, path=self.path / f"{filename}.pkl"
122122
)
123123
else:
124-
self._entries[name] = self.default_node(name=name) # type: ignore[call-arg]
124+
self._entries[name] = self.default_node(name=name)
125125
self.path.joinpath(f"{filename}-node.pkl").write_bytes( # type: ignore[union-attr]
126126
pickle.dumps(self._entries[name])
127127
)

src/_pytask/execute.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -301,10 +301,8 @@ def pytask_execute_task_teardown(session: Session, task: PTask) -> None:
301301
return
302302

303303
collect_provisional_products(session, task)
304-
missing_nodes: list[Any] = [ # type: ignore[var-annotated]
305-
node
306-
for node in tree_leaves(task.produces) # type: ignore[arg-type]
307-
if not node.state()
304+
missing_nodes: list[Any] = [
305+
node for node in tree_leaves(task.produces) if not node.state()
308306
]
309307
if missing_nodes:
310308
paths = session.config["paths"]

0 commit comments

Comments
 (0)