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

Support union types and all templates in register_pre_build_hook #1275

Open
daturkel opened this issue Nov 25, 2024 · 0 comments
Open

Support union types and all templates in register_pre_build_hook #1275

daturkel opened this issue Nov 25, 2024 · 0 comments
Labels
type:enhancement A general enhancement

Comments

@daturkel
Copy link

Is your feature request related to a problem? Please describe.

Currently, if I want to apply a pre-build hook to both containers and scripts, I need to register the same hook twice, once for the Script type and once for Container. Similarly, there is no easy way to register a pre-build hook that will apply to all templates regardless of template type.

Describe the solution you'd like

  1. Pre-build hooks should support union types, e.g.
ScriptOrContainer = TypeVar('ScriptOrContainer', bound=Union[Script, Container])

# This hook should be applied to scripts and containers
@register_pre_build_hook
def foo(template: T) -> T:
    ...
  1. There should be an easy way to set a pre-build hook to support all template types.

Describe alternatives you've considered

The best alternative now is to define the hook in a native python function, and then wrap that function in a registered hook once per each type it needs to support.

@elliotgunton elliotgunton added the type:enhancement A general enhancement label Nov 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

2 participants