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

Repeated Keys in Nested List #160

Closed
efanibi25 opened this issue Sep 12, 2022 · 2 comments · Fixed by #397
Closed

Repeated Keys in Nested List #160

efanibi25 opened this issue Sep 12, 2022 · 2 comments · Fixed by #397
Labels
bug Something isn't working

Comments

@efanibi25
Copy link

efanibi25 commented Sep 12, 2022

This was my first day trying out this module
I notice that repeated key names may lead to undesirable results. Even if they are separated by level

I have given out some examples I tested out. It really only causes issues for two of them

@efanibi25 efanibi25 added the bug Something isn't working label Sep 12, 2022
@efanibi25
Copy link
Author

efanibi25 commented Sep 12, 2022

Example 1

#!/usr/bin/env python3.9

from jsonargparse import ArgumentParser, ActionConfigFile
import os


defaultconfigPath = os.path.join(os.path.dirname(
    os.path.realpath(__file__)), "config.json")
p = ArgumentParser()
p.default_config_files = [defaultconfigPath]
p.add_argument("--test")



{
  "test": "value"
}



Example 2: Does not work

#!/usr/bin/env python3.9

from jsonargparse import ArgumentParser, ActionConfigFile
import os


defaultconfigPath = os.path.join(os.path.dirname(
    os.path.realpath(__file__)), "config.json")
p = ArgumentParser()
p.default_config_files = [defaultconfigPath]



p2 = ArgumentParser()
p2.add_argument("--test")

subcommands = p.add_subcommands()
subcommands.add_subcommand('test', p2)

{
  "test": {
    "test":"value"
  }
}




Example 3

from jsonargparse import ArgumentParser, ActionConfigFile
import os


defaultconfigPath = os.path.join(os.path.dirname(
    os.path.realpath(__file__)), "config.json")
p = ArgumentParser()
p.default_config_files = [defaultconfigPath]



p2 = ArgumentParser()
p2.add_argument("--test2")

subcommands = p.add_subcommands()
subcommands.add_subcommand('test', p2)

{
  "test": {
    "test2":"value"
  }
}




Example 4
#!/usr/bin/env python3.9

from jsonargparse import ArgumentParser, ActionConfigFile
import os


defaultconfigPath = os.path.join(os.path.dirname(
    os.path.realpath(__file__)), "config.json")
p = ArgumentParser()
p.default_config_files = [defaultconfigPath]



p2 = ArgumentParser()

p3 = ArgumentParser()
p3.add_argument("--test2")


subcommands = p.add_subcommands()
subcommands.add_subcommand('test', p2)


subcommands = p2.add_subcommands()
subcommands.add_subcommand('test2', p3)


{
  "test": {
    "test2":{
      "test2":"value"
    }
  }
}


Examples 6 : Does not Work
#!/usr/bin/env python3.9

from jsonargparse import ArgumentParser, ActionConfigFile
import os


defaultconfigPath = os.path.join(os.path.dirname(
    os.path.realpath(__file__)), "config.json")
p = ArgumentParser()
p.default_config_files = [defaultconfigPath]



p2 = ArgumentParser()

p3 = ArgumentParser()
p3.add_argument("--test")


subcommands = p.add_subcommands()
subcommands.add_subcommand('test', p2)


subcommands = p2.add_subcommands()
subcommands.add_subcommand('test', p3)



{
  "test": {
    "test":{
      "test":"value"
    }
  }
}

Example 7

#!/usr/bin/env python3.9

from jsonargparse import ArgumentParser, ActionConfigFile
import os


defaultconfigPath = os.path.join(os.path.dirname(
    os.path.realpath(__file__)), "config.json")
p = ArgumentParser()
p.default_config_files = [defaultconfigPath]



p2 = ArgumentParser()

p3 = ArgumentParser()
p3.add_argument("--test2")


subcommands = p.add_subcommands()
subcommands.add_subcommand('test', p2)


subcommands = p2.add_subcommands()
subcommands.add_subcommand('test2', p3)



{
  "test": {
    "test2":{
      "test2":"value"
    }
  }
}

Example 8

#!/usr/bin/env python3.9

from jsonargparse import ArgumentParser, ActionConfigFile
import os


defaultconfigPath = os.path.join(os.path.dirname(
    os.path.realpath(__file__)), "config.json")
p = ArgumentParser()
p.default_config_files = [defaultconfigPath]



p2 = ArgumentParser()

p3 = ArgumentParser()
p3.add_argument("--test3")


subcommands = p.add_subcommands()
subcommands.add_subcommand('test', p2)


subcommands = p2.add_subcommands()
subcommands.add_subcommand('test', p3)



{
  "test": {
    "test":{
      "test3":"value"
    }
  }
}

Example 2 Errors out with

'Key is required if value not a Namespace.'

Example 6 Errors out with

Problem in default config file "...." :: "subcommand" is required but not given or its value is None.

@mauvilsa
Copy link
Member

@efanibi25 thank you for reporting. Just as an update, I have looked at this but unfortunately it is not an easy fix. This will need some refactoring of the code related to subcommands, thus the fix will take a bit more of time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants