Title: Argparse logs incorrect ambiguous option · Issue #125254 · python/cpython · GitHub
Open Graph Title: Argparse logs incorrect ambiguous option · Issue #125254 · python/cpython
X Title: Argparse logs incorrect ambiguous option · Issue #125254 · python/cpython
Description: Bug report Bug description: Given this example script import argparse class CsvListAction(argparse.Action): """ argparse Action to convert "a,b,c" into ["a", "b", "c"] """ def __call__(self, parser, namespace, values, option_string=None)...
Open Graph Description: Bug report Bug description: Given this example script import argparse class CsvListAction(argparse.Action): """ argparse Action to convert "a,b,c" into ["a", "b", "c"] """ def __call__(self, parser...
X Description: Bug report Bug description: Given this example script import argparse class CsvListAction(argparse.Action): """ argparse Action to convert "a,b,c" into ["a", &quo...
Opengraph URL: https://github.com/python/cpython/issues/125254
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Argparse logs incorrect ambiguous option","articleBody":"# Bug report\n\n### Bug description:\n\nGiven this example script\n\n```python\nimport argparse\nclass CsvListAction(argparse.Action):\n \"\"\"\n argparse Action to convert \"a,b,c\" into [\"a\", \"b\", \"c\"]\n \"\"\"\n\n def __call__(self, parser, namespace, values, option_string=None):\n # Conversion to dict removes duplicates while preserving order\n items = list(dict.fromkeys(values.split(\",\")).keys())\n setattr(namespace, self.dest, items)\n\n\nparser = argparse.ArgumentParser(description=\"Testing\")\n\nparser.add_argument(\"directory\", type=str, help=\"path to find files\")\nparser.add_argument(\n \"--output\",\n type=str,\n help=\"name of output file to produce\",\n)\n\nname_args_group = parser.add_mutually_exclusive_group()\nname_args_group.add_argument(\n \"--name-exclude\",\n action=CsvListAction,\n help=\"Comma-separated set of name ID(s) to exclude\",\n)\nname_args_group.add_argument(\n \"--name-include\",\n action=CsvListAction,\n help=\"Comma-separated set of name ID(s) to include\",\n)\n\n\nparser.add_argument(\n \"--path-exclude\",\n action=CsvListAction,\n default=[],\n help=\"Comma-separated set of UNIX glob patterns to exclude\",\n)\nparser.add_argument(\n \"--path-include\",\n action=CsvListAction,\n default=[],\n help=\"Comma-separated set of UNIX glob patterns to include\",\n)\nparser.parse_args()\n\n```\n**Notice the cli args are `name-exclude` and `name-include`**\n\nRun the following command, which incorrectly puts the arg as `--name`\n`python argparse_mini.py /some/path --output here.txt --name something --path-exclude *request.py`\n\nIf you run it with Python 3.12.2 or below, the resulting log statement is what we expect\n`argparse_mini.py: error: ambiguous option: --name could match --name-exclude, --name-include`\n\nHowever, tested with 3.12.7 and the log statement instead is\n`argparse_mini.py: error: ambiguous option: *request.py could match --name-exclude, --name-include`\n\nwhich is clearly incorrect, as `*request.py` was the argument to a different CLI option\n\n### CPython versions tested on:\n\n3.11, 3.12\n\n### Operating systems tested on:\n\nmacOS\n\n\u003c!-- gh-linked-prs -->\n### Linked PRs\n* gh-125273\n* gh-125359\n* gh-125360\n\u003c!-- /gh-linked-prs -->\n","author":{"url":"https://github.com/clavedeluna","@type":"Person","name":"clavedeluna"},"datePublished":"2024-10-10T12:31:43Z","url":"https://github.com/python/cpython/issues/125254"}
| 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:e0152de6-b12c-ab55-f590-38bb347b8e8a |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | A0A8:27AD12:F6E55C:14B23CB:6B005C7F |
| html-safe-nonce | e0a2c60b671afc391e17f79fee10dc9240583e04d45f64da7d0e8c49223e93ef |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBMEE4OjI3QUQxMjpGNkU1NUM6MTRCMjNDQjo2QjAwNUM3RiIsInZpc2l0b3JfaWQiOiI2MTQwNDQ2NTkyMzQ1MzMyODYzIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 115e7ee56c1ac5d683b3e3f615bd48e29063953500a377b3dee34a13723fd31e |
| hovercard-subject-tag | issue:2578710756 |
| 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/125254/issue_layout |
| twitter:image | https://opengraph.githubassets.com/11cb88a81c64702d5eb736e903d90574142072686104b7d71a0b9c7e1bd62600/python/cpython/issues/125254 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/11cb88a81c64702d5eb736e903d90574142072686104b7d71a0b9c7e1bd62600/python/cpython/issues/125254 |
| og:image:alt | Bug report Bug description: Given this example script import argparse class CsvListAction(argparse.Action): """ argparse Action to convert "a,b,c" into ["a", "b", "c"] """ def __call__(self, parser... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | clavedeluna |
| hostname | github.com |
| expected-hostname | github.com |
| None | 29be975efff6507a5d135de9c7d634cf7ff8f0c55222a64386ab3202209aaf73 |
| 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 | eacd927ba6112e3b01ba99c762bd699a4a4f5df7 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width