Title: argparse: ambiguous option reported with primary parser · Issue #109990 · python/cpython · GitHub
Open Graph Title: argparse: ambiguous option reported with primary parser · Issue #109990 · python/cpython
X Title: argparse: ambiguous option reported with primary parser · Issue #109990 · python/cpython
Description: Bug report Bug description: When we have sub_parser argument which is substring of main parser, getting error as ambiguous option python sample.py show -foo "data" usage: PROG [-h] [-foobar FOOBAR] [-foobar1 FOOBAR1] {show} ... PROG: err...
Open Graph Description: Bug report Bug description: When we have sub_parser argument which is substring of main parser, getting error as ambiguous option python sample.py show -foo "data" usage: PROG [-h] [-foobar FOOBAR]...
X Description: Bug report Bug description: When we have sub_parser argument which is substring of main parser, getting error as ambiguous option python sample.py show -foo "data" usage: PROG [-h] [-foob...
Opengraph URL: https://github.com/python/cpython/issues/109990
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"argparse: ambiguous option reported with primary parser","articleBody":"# Bug report\r\n\r\n### Bug description:\r\n\r\nWhen we have sub_parser argument which is substring of main parser, getting error as ambiguous option\r\n\r\npython sample.py show -foo \"data\"\r\nusage: PROG [-h] [-foobar FOOBAR] [-foobar1 FOOBAR1] {show} ...\r\nPROG: error: ambiguous option: -foo could match -foobar, -foobar1\r\n\r\nObserving with python 3.11.3. Earlier it works fine with python 3.5\r\n\r\n```python\r\n# Add a code block here, if required\r\nparser = argparse.ArgumentParser(prog='PROG', allow_abbrev=False)\r\nparser.add_argument('-foobar', action='store')\r\nparser.add_argument('-foobar1', action='store')\r\nsub_parser = parser.add_subparsers(dest='command')\r\n# Show\r\nsub_parser_show = sub_parser.add_parser('show', help='Print Client ID for a specific environment',\r\n\t\t\t\t\t\t\t\t\t\t\tdescription= 'Print Client ID for a specific environment')\r\nsub_parser_show.add_argument('-foo', dest = 'env_name', action='store', \r\n\t\t\t\t\t\t\t\t\t\thelp='Environment name Eg: \"development\"')\r\n\r\nargs = parser.parse_args()\r\nprint (args)\r\n```\r\n\r\n\r\n### CPython versions tested on:\r\n\r\n3.11\r\n\r\n### Operating systems tested on:\r\n\r\nLinux\n\n\u003c!-- gh-linked-prs -->\n### Linked PRs\n* gh-124000\n\u003c!-- /gh-linked-prs -->\n","author":{"url":"https://github.com/getsimonz","@type":"Person","name":"getsimonz"},"datePublished":"2023-09-27T21:43:51Z","url":"https://github.com/python/cpython/issues/109990"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:01c6f687-b58d-e18f-3995-7d5f12f82a18 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | C7E2:1AC37C:D70B54:11FA361:6B00545C |
| html-safe-nonce | dee638686da286f5bdf6e87ea646f5c604ba4e672cee8057b9ce02cce66ad19b |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDN0UyOjFBQzM3QzpENzBCNTQ6MTFGQTM2MTo2QjAwNTQ1QyIsInZpc2l0b3JfaWQiOiIyMjMxODkwMTA4MDMyNzY3MDY4IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | e7f046facfcec549135feb2648fab0c337c31d63d29a1c2b367497e9130fc4ad |
| hovercard-subject-tag | issue:1916377686 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python/cpython/109990/issue_layout |
| twitter:image | https://opengraph.githubassets.com/3b793252d2943c96c1aabad4b41efa7d34e71bbb3a1b0d48ef2a7dde688a1c39/python/cpython/issues/109990 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/3b793252d2943c96c1aabad4b41efa7d34e71bbb3a1b0d48ef2a7dde688a1c39/python/cpython/issues/109990 |
| og:image:alt | Bug report Bug description: When we have sub_parser argument which is substring of main parser, getting error as ambiguous option python sample.py show -foo "data" usage: PROG [-h] [-foobar FOOBAR]... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | getsimonz |
| hostname | github.com |
| expected-hostname | github.com |
| None | f420f4996e6b1ff1ccd6d7683f8134f4b5f0f8a50124c210dbfe7490e5644abb |
| turbo-cache-control | no-preview |
| go-import | github.com/python/cpython git https://github.com/python/cpython.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 81598961 |
| octolytics-dimension-repository_nwo | python/cpython |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 81598961 |
| octolytics-dimension-repository_network_root_nwo | python/cpython |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 26e00df917aba0f128135dc073ea0c5e33a70d40 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width