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

fix arg name conflict positional module_name and named module_name #932

Merged
merged 1 commit into from
Jun 1, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions hamilton/plugins/jupyter_magic.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ def resolve_config_arg(self, config_arg) -> Union[bool, dict]:
return config

@magic_arguments() # needed on top to enable parsing
@argument("module_name", nargs="?", help="Name for the module defined in this cell.")
@argument("name", nargs="?", help="Name for the module defined in this cell.")
@argument(
"-m",
"--module_name",
Expand Down Expand Up @@ -311,8 +311,15 @@ def B(A: int) -> bool:
if config is False:
return

# resolve the values of args
module_name = args.module_name
# check if string instance because module_name has default `True`
if isinstance(args.name, str) and isinstance(args.module_name, str):
print(
f"ValueError: Received both positional arg name={args.name} and named arg module_name={args.module_name}. Pass either one."
)
return

# merged the positional arg `name` with named arg `module_name` for backwards compatibility
module_name = args.module_name if isinstance(args.module_name, str) else args.name
base_builder = self.shell.user_ns[args.builder] if args.builder else driver.Builder()
inputs = self.shell.user_ns[args.inputs] if args.inputs else {}
overrides = self.shell.user_ns[args.overrides] if args.overrides else {}
Expand Down