Skip to content

Commit 134d241

Browse files
committed
Fix annotation eval and ty overrides
1 parent 807edd1 commit 134d241

3 files changed

Lines changed: 16 additions & 5 deletions

File tree

pyproject.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,12 @@ filterwarnings = [
173173
[tool.ty.rules]
174174
unused-ignore-comment = "error"
175175

176+
[[tool.ty.overrides]]
177+
include = ["src/_pytask/_version.py"]
178+
179+
[tool.ty.overrides.rules]
180+
unused-ignore-comment = "ignore"
181+
176182
[tool.ty.src]
177183
exclude = ["src/_pytask/_hashlib.py"]
178184

src/_pytask/_inspect.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from inspect import get_annotations as _get_annotations_from_inspect
77
from typing import TYPE_CHECKING
88
from typing import Any
9+
from typing import cast
910

1011
if TYPE_CHECKING:
1112
from collections.abc import Callable
@@ -57,7 +58,9 @@ def get_annotations(
5758
raw_annotations = _get_annotations_from_inspect(
5859
obj, globals=globals, locals=locals, eval_str=False
5960
)
60-
evaluation_globals = obj.__globals__ if globals is None else globals
61+
evaluation_globals = cast(
62+
"dict[str, Any]", obj.__globals__ if globals is None else globals
63+
)
6164
evaluation_locals = evaluation_globals if locals is None else locals
6265
evaluated_annotations = {}
6366
for name, expression in raw_annotations.items():

src/_pytask/click.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,11 @@
3535

3636

3737
if importlib.metadata.version("click") < "8.2":
38-
from click.parser import split_opt
38+
from click.parser import split_opt as _split_opt
3939
else:
40-
from click.parser import _split_opt as split_opt # ty: ignore[unresolved-import]
40+
from click.parser import _split_opt
41+
42+
split_opt = _split_opt
4143

4244

4345
class EnumChoice(Choice):
@@ -249,7 +251,7 @@ def _print_options(group_or_command: Command | DefaultGroup, ctx: Context) -> No
249251
if param.metavar:
250252
opt2 += Text(f" {param.metavar}", style="metavar")
251253
elif isinstance(param.type, click.Choice):
252-
choices = "[" + "|".join(param.type.choices) + "]"
254+
choices = "[" + "|".join(param.type.choices) + "]" # ty: ignore[no-matching-overload]
253255
opt2 += Text(f" {choices}", style="metavar", overflow="fold")
254256

255257
help_text = _format_help_text(param, ctx)
@@ -327,7 +329,7 @@ def _format_help_text( # noqa: C901, PLR0912, PLR0915
327329
elif param.is_bool_flag and param.secondary_opts: # type: ignore[attr-defined]
328330
# For boolean flags that have distinct True/False opts,
329331
# use the opt without prefix instead of the value.
330-
default_string = split_opt(
332+
default_string = split_opt( # ty: ignore[call-non-callable]
331333
(param.opts if param.default else param.secondary_opts)[0]
332334
)[1]
333335
elif (

0 commit comments

Comments
 (0)