Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Nesting has confusing, hidden, behaviour

See original GitHub issue

Describe the bug It took me a lot of experimentation to find out that parameters are only prefixed with their nested group name if the name of the nested parameter conflicts with another. I expected it to prefix it with the nested group name at all times, and I think it should do this.

It should do this because of the following situation:

  • I have a dataclass of parameters I want to re-use in multiple places (lets call it A, with parameters a and b)
  • If I use it in one place which only has a single nested group of type A, then I specify arguments as --a asdf and --b asdf.
  • If I use it in a second place which has multiple nested groups then if those groups also specify parameters of a and b then suddenly my API has silently changed from --a asdf to --A.a asdf without touching that bit of code

There is a second situation where this is useful as well: I define a dataclass with parameter names that make sense in the context of the name of the class they are defined under. However, if you take those names out of context without the name of the containing class, then they are ill-defined and therefore the resulting CLI is confusing. e.g.

class Bananas:
    count: int
class MyCli:
    bananas: Bananas

Gives the following CLI helptext:

usage: [-h] --count int error: the following arguments are required: --count

Note that count is now completely meaningless. I can obviously add a docstring to explain it, but that means that every parameter docstring in Bananas must make sure it references Bananas.

To Reproduce Comment/uncomment out B from MyCli and see the output of --help change.

from simple_parsing import ArgumentParser
from dataclasses import dataclass
from typing import *

class A:
    a: str
    b: str
class B:
    a: str
    b: str

class MyCli:

    A: A
    B: B  # Comment/uncomment this.

parser = ArgumentParser()
parser.add_arguments(MyCli, dest="args")
args = parser.parse_args()

Expected behavior Subgroups should always include the group name when specifying their parameters.

I.e. in the above example, without B, you should get:

usage: [-h] -a str -b str error: the following arguments are required: -A.a/--A.a, -A.b/--A.b

whereas you currently get this:

usage: [-h] -a str -b str error: the following arguments are required: -a/--a, -b/--b

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

jordiaecommented, Mar 17, 2021

Hi @lebrice, sorry for re-opening the issue. I think there was a misunderstanding (my fault). Passing the ConflictResolution.EXPLICIT value to the ArgumentParser constructor’s conflict_resolution argument is only used if there is a conflict. Instead, I want to force prefixing for all nested arguments, even if there is no potential for a conflict.

jordiaecommented, Mar 19, 2021

Hey @jordiae thats fair, you can use add_dest_to_option_strings argument to the ArgumentParser constructor, which won’t do exactly what you want, but it will at least add the option for you to reference everything with the fully qualified path.

Let me know if thats sufficient!

Hi, many thanks for the idea!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why is my dog nesting? - Wag!
Your dog may be nesting because she is close to delivering puppies. ... Your dog can also experience behavior changes such as moodiness,...
Read more >
Behavioral theorists operating within this framework must be careful to distinguish between nesting and chaining. Explanations are chained when the explanandum ...
Read more >
Distraction display - Wikipedia
Distraction displays are sometimes classified more generically under "nest protection behaviors" along with aggressive displays such as mobbing.
Read more >
Nesting Behavior - an overview | ScienceDirect Topics
The adults are separable by the malar yellow “moustaches” of A. latirostris, which the birds can hide or exhibit according to the circumstances;...
Read more >
The Nesting Instinct of Humanity – Richard Collison
to confuse by removing or obscuring something that has guided a person, group, or culture, as customs, moral standards, etc.: Society has been...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Post

No results found

github_iconTop Related Hashnode Post

No results found