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

Mypy misc error using new Workflow/TemplateSet decorators #1182

Open
3 of 7 tasks
alicederyn opened this issue Aug 29, 2024 · 0 comments
Open
3 of 7 tasks

Mypy misc error using new Workflow/TemplateSet decorators #1182

alicederyn opened this issue Aug 29, 2024 · 0 comments
Labels
type:bug A general bug

Comments

@alicederyn
Copy link
Collaborator

alicederyn commented Aug 29, 2024

Pre-bug-report checklist

1. This bug can be reproduced using pure Argo YAML

If yes, it is more likely to be an Argo bug unrelated to Hera. Please double check before submitting an issue to Hera.

2. I have searched for existing issues

  • Yes

3. This bug occurs in Hera when...

  • exporting to YAML
  • submitting to Argo
  • running on Argo with the Hera runner
  • other: Type checking

Bug report

Describe the bug
A clear and concise description of what the bug is:

Mypy is raising an error on code using the new Workflow/TemplateSet decorators:

Error log if applicable:

error: Attribute function "script" with type "Callable[[DefaultNamedArg(Any, 'volumes'), DefaultNamedArg(Any, 'volume_devices'), DefaultNamedArg(Any, 'volume_mounts'), DefaultNamedArg(Any, 'resources'), DefaultNamedArg(Any, 'metrics'), DefaultNamedArg(Any, 'active_deadline_seconds'), DefaultNamedArg(Any, 'affinity'), DefaultNamedArg(Any, 'archive_location'), DefaultNamedArg(Any, 'automount_service_account_token'), DefaultNamedArg(Any, 'daemon'), DefaultNamedArg(Any, 'executor'), DefaultNamedArg(Any, 'fail_fast'), DefaultNamedArg(Any, 'host_aliases'), DefaultNamedArg(Any, 'init_containers'), DefaultNamedArg(Any, 'memoize'), DefaultNamedArg(Any, 'annotations'), DefaultNamedArg(Any, 'labels'), DefaultNamedArg(Any, 'name'), DefaultNamedArg(Any, 'node_selector'), DefaultNamedArg(Any, 'parallelism'), DefaultNamedArg(Any, 'http'), DefaultNamedArg(Any, 'plugin'), DefaultNamedArg(Any, 'pod_spec_patch'), DefaultNamedArg(Any, 'priority'), DefaultNamedArg(Any, 'priority_class_name'), DefaultNamedArg(Any, 'retry_strategy'), DefaultNamedArg(Any, 'scheduler_name'), DefaultNamedArg(Any, 'pod_security_context'), DefaultNamedArg(Any, 'service_account_name'), DefaultNamedArg(Any, 'sidecars'), DefaultNamedArg(Any, 'synchronization'), DefaultNamedArg(Any, 'timeout'), DefaultNamedArg(Any, 'tolerations'), DefaultNamedArg(Any, 'image'), DefaultNamedArg(Any, 'image_pull_policy'), DefaultNamedArg(Any, 'liveness_probe'), DefaultNamedArg(Any, 'ports'), DefaultNamedArg(Any, 'readiness_probe'), DefaultNamedArg(Any, 'startup_probe'), DefaultNamedArg(Any, 'stdin'), DefaultNamedArg(Any, 'stdin_once'), DefaultNamedArg(Any, 'termination_message_path'), DefaultNamedArg(Any, 'termination_message_policy'), DefaultNamedArg(Any, 'tty'), DefaultNamedArg(Any, 'inputs'), DefaultNamedArg(Any, 'outputs'), DefaultNamedArg(Any, 'env'), DefaultNamedArg(Any, 'env_from'), DefaultNamedArg(Any, 'container_name'), DefaultNamedArg(Any, 'args'), DefaultNamedArg(Any, 'command'), DefaultNamedArg(Any, 'lifecycle'), DefaultNamedArg(Any, 'security_context'), DefaultNamedArg(Any, 'source'), DefaultNamedArg(Any, 'working_dir'), DefaultNamedArg(Any, 'add_cwd_to_sys_path'), DefaultNamedArg(Any, 'constructor'), KwArg(Any)], Callable[[Callable[FuncIns, FuncR]], Callable[FuncIns, FuncR]]]" does not accept self argument  [misc]

To Reproduce
Full Hera code to reproduce the bug:

from hera.shared import global_config
from hera.workflows import Input, Output, TemplateSet

global_config.experimental_features["decorator_syntax"] = True

template_set = TemplateSet()
@template_set.script()
def simple_script(_: Input) -> Output:
    return Output()

Expected behavior
A clear and concise description of what you expected to happen:

No mypy errors.

Environment

  • Hera Version: 5.16.2
  • Python Version: 3.11.8
  • Argo Version: N/A

Additional context
I believe the issue is that the type hints being added by the _add_type_hints decorator do not include a self parameter, only the kwargs copied from the PydanticKwargs param spec:

def _add_type_hints(
_pydantic_obj: Callable[PydanticKwargs, PydanticCls],
) -> Callable[
...,
Callable[
PydanticKwargs, # this adds type hints to the underlying *library* function kwargs
Callable[ # we will return a function that is a decorator
[Callable[FuncIns, FuncR]], # taking underlying *user* function
Callable[FuncIns, FuncR], # and returning it
],
],
]:
"""Adds type hints to the decorated function."""
return lambda func: func

@alicederyn alicederyn added the type:bug A general bug label Aug 29, 2024
@elliotgunton elliotgunton added this to the HEP0001 - new decorators milestone Sep 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:bug A general bug
Projects
None yet
Development

No branches or pull requests

2 participants