René's URL Explorer Experiment


Title: Argparse: "Default" interacts incorrectly/non-intuitively with action='append' and action='extend' · Issue #110131 · python/cpython · GitHub

Open Graph Title: Argparse: "Default" interacts incorrectly/non-intuitively with action='append' and action='extend' · Issue #110131 · python/cpython

X Title: Argparse: "Default" interacts incorrectly/non-intuitively with action='append' and action='extend' · Issue #110131 · python/cpython

Description: Bug report Bug description: The documentation for default claims: The default keyword argument of add_argument(), whose value defaults to None, specifies what value should be used if the command-line argument is not present which (implic...

Open Graph Description: Bug report Bug description: The documentation for default claims: The default keyword argument of add_argument(), whose value defaults to None, specifies what value should be used if the command-li...

X Description: Bug report Bug description: The documentation for default claims: The default keyword argument of add_argument(), whose value defaults to None, specifies what value should be used if the command-li...

Opengraph URL: https://github.com/python/cpython/issues/110131

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Argparse: \"Default\" interacts incorrectly/non-intuitively with action='append' and action='extend'","articleBody":"# Bug report\n\n### Bug description:\n\nThe documentation for `default` claims:\n> The default keyword argument of [add_argument()](https://docs.python.org/3/library/argparse.html#argparse.ArgumentParser.add_argument), whose value defaults to None, specifies what value should be used if the command-line argument is not present\nwhich (implicitly) sets the expectation that the default is not used if the command-line argument is present\n\nin it's defense, the strange behaviour is documented in `append` but not `extend`\n> If the default value is non-empty, the default elements will be present in the parsed value for the option, with any values from the command line appended after those default values\n\nHowever, this behaviour is non-intuitive. The fact that the values will be prepended to the end-user's input is not obvious, furthermore, the end-user is *unable* to specify a set of parameters that don't contain undesired default values.\n\n```python\n    DEFAULT_SET=['a','b','c','d']\n    parser = argparse.ArgumentParser()\n    parser.add_argument('--items',nargs='+',action='extend',dest='items',choices=DEFAULT_SET,default=DEFAULT_SET)\n    args = parser.parse_args()\n\n    print(args.items)\n```\n> $ python3 example.py --items a --items b c # expected: items will contain 'a', 'b', and 'c'\n['a', 'b', 'c', 'd', 'a', 'b', 'c']\n\n\nNow it's fair to say that there's a workaround:\n\n```python\n    parser.add_argument('--items',nargs='+',action='extend',dest='items',choices=DEFAULT_SET,default=None)\n    args = parser.parse_args()\n    if args.items == None:\n        args.items = DEFAULT_SET \n```\nhowever, isn't this the pattern that `default=` aims to eliminate/alleviate in the first place? \n\nIf the purpose of DEFAULT is to supply a value in the absense of user input, the fact that it supplies a value even when the user supplies input is an undesired *side effect* and not really default behaviour.\n\nIf the code needs to *always* be processing a set of values regardless of user input, then that really should be clearly stated in the code/logic, rather than a side effect of the input parsing\n```python\n    do_something(DEFAULT_SET + args.items) # no ambiguity\n```\n\nhope this makes sense. thank you!\n\n### CPython versions tested on:\n\n3.8\n\n### Operating systems tested on:\n\nmacOS\n\n\u003c!-- gh-linked-prs -->\n### Linked PRs\n* gh-158155\n* gh-158352\n* gh-158353\n* gh-158354\n\u003c!-- /gh-linked-prs -->\n","author":{"url":"https://github.com/rhetzler","@type":"Person","name":"rhetzler"},"datePublished":"2023-09-30T00:52:27Z","url":"https://github.com/python/cpython/issues/110131"}

react-profiling0
react-import-mapreact,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-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:3ba487dc-5ae2-c454-5f15-ebce5ef13617
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-id8F26:323204:1511684:1BC9CEB:6B01FA8C
html-safe-noncef36c8feead067e7eaffa3933af214baf4105d0297dea2041215c36fa1ed373fb
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4RjI2OjMyMzIwNDoxNTExNjg0OjFCQzlDRUI6NkIwMUZBOEMiLCJ2aXNpdG9yX2lkIjoiMzQ0NTY3ODQ0NjA0OTYyMjY2OCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9
visitor-hmac07494fa8b6f9321f55dfd5770f06aaddd25e062961d53f04d4dfa00191279375
hovercard-subject-tagissue:1920042693
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python/cpython/110131/issue_layout
twitter:imagehttps://opengraph.githubassets.com/52ae5f6a00ef34ab01fde66275343f930275efb5141fc332902fba81d95ac59d/python/cpython/issues/110131
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/52ae5f6a00ef34ab01fde66275343f930275efb5141fc332902fba81d95ac59d/python/cpython/issues/110131
og:image:altBug report Bug description: The documentation for default claims: The default keyword argument of add_argument(), whose value defaults to None, specifies what value should be used if the command-li...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernamerhetzler
hostnamegithub.com
expected-hostnamegithub.com
None87e774ee7c6b3bee0490394e4d3e57ec9dbc956f74b87ea685dc8996c1676456
turbo-cache-controlno-preview
go-importgithub.com/python/cpython git https://github.com/python/cpython.git
octolytics-dimension-user_id1525981
octolytics-dimension-user_loginpython
octolytics-dimension-repository_id81598961
octolytics-dimension-repository_nwopython/cpython
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id81598961
octolytics-dimension-repository_network_root_nwopython/cpython
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release423dbb54c5e7bfecc838eb387c1435eb3d0e760d
ui-targetfull
theme-color#1e2327
color-schemelight dark
react-app-nameissues

Links:

Skip to contenthttps://github.com/python/cpython/issues/110131#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fissues%2F110131
GitHubRepository hosting, code review, and collaborationhttps://github.com/platform
CopilotAI coding agent for tasks, projects, and automated workhttps://github.com/features/copilot
ActionsCI/CD and automationhttps://github.com/features/actions
Code QualityQuality analysis, fixes, and enforcementhttps://github.com/features/code-quality
CodespacesCloud development environmentshttps://github.com/features/codespaces
Code SecurityVulnerability detection and remediationhttps://github.com/security/advanced-security/code-security
Secret ProtectionSecret scanning and leak preventionhttps://github.com/security/advanced-security/secret-protection
All Featureshttps://github.com/features
Documentationhttps://docs.github.com/en
Traininghttps://learn.github.com/skills
Certificationshttps://learn.github.com/credentials
Build with Copilothttps://github.com/features/ai
Customize Copilothttps://docs.github.com/en/copilot/how-tos/copilot-on-github/customize-copilot/customize-copilot-overview
Integrationshttps://github.com/marketplace
Trending reposhttps://github.com/trending
GitHub Sponsorshttps://github.com/open-source/sponsors
Developer articleshttps://github.com/resources/articles
ChangelogYour source for the latest features, improvements, and fixes across GitHub products, all in one place.https://github.blog/changelog/
Enterpriseshttps://github.com/enterprise
Teamhttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
See all industrieshttps://github.com/solutions/industry
Why GitHubhttps://github.com/why-github
Customer Storieshttps://github.com/customer-stories
Business insightshttps://github.com/solutions/executive-insights
Trust Centerhttps://github.com/trust-center
GitHub Advanced SecurityEnterprise-grade code securityhttps://github.com/security/advanced-security
Copilot for businessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Documentationhttps://docs.github.com/en
Resource centerhttps://github.com/resources
Bloghttps://github.blog/
Events & webinarshttps://github.com/resources/events
Community Forumhttps://github.com/orgs/community/discussions
Customer Storieshttps://github.com/customer-stories
Integrationshttps://github.com/marketplace
Customer supporthttps://help.github.com/
Traininghttps://learn.github.com/skills
GitHub Statushttps://www.githubstatus.com/
Abouthttps://github.com/about
Partnershttps://github.com/partners
Changeloghttps://github.blog/changelog/
GitHub UniverseThe event for developers, by developers — talks, workshops, and what’s next for GitHub.https://githubuniverse.com/
Pricinghttps://github.com/pricing
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fissues%2F110131
Sign uphttps://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=python%2Fcpython
Reloadhttps://github.com/python/cpython/issues/110131
Reloadhttps://github.com/python/cpython/issues/110131
Reloadhttps://github.com/python/cpython/issues/110131
pythonhttps://github.com/python
cpythonhttps://github.com/python/cpython
Codehttps://github.com/python/cpython
Issues5k+ (5k+)https://github.com/python/cpython/issues
Pull requests2.4k (2.4k)https://github.com/python/cpython/pulls
Actionshttps://github.com/python/cpython/actions
Projectshttps://github.com/python/cpython/projects
Security and qualityhttps://github.com/python/cpython/security
Insightshttps://github.com/python/cpython/insights
https://github.com/python/cpython
New issuehttps://github.com/login?return_to=https://github.com/python/cpython/issues/110131
New issuehttps://github.com/login?return_to=https://github.com/python/cpython/issues/110131
#158155https://github.com/python/cpython/pull/158155
Argparse: "Default" interacts incorrectly/non-intuitively with action='append' and action='extend'https://github.com/python/cpython/issues/110131#top
#158155https://github.com/python/cpython/pull/158155
3.12only security fixeshttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%223.12%22
3.13only security fixeshttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%223.13%22
3.14bugs and security fixeshttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%223.14%22
docsDocumentation in the Doc dirhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22docs%22
stdlibStandard Library Python modules in the Lib/ directoryhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22stdlib%22
https://github.com/rhetzler
rhetzlerhttps://github.com/rhetzler
on Sep 30, 2023https://github.com/python/cpython/issues/110131#issue-1920042693
add_argument()https://docs.python.org/3/library/argparse.html#argparse.ArgumentParser.add_argument
gh-110131: Document how a non-empty default works with append and extend #158155https://github.com/python/cpython/pull/158155
[3.15] gh-110131: Document how a non-empty default works with append and extend (GH-158155) #158352https://github.com/python/cpython/pull/158352
[3.14] gh-110131: Document how a non-empty default works with append and extend (GH-158155) #158353https://github.com/python/cpython/pull/158353
[3.13] gh-110131: Document how a non-empty default works with append and extend (GH-158155) #158354https://github.com/python/cpython/pull/158354
rhetzlerhttps://github.com/rhetzler
type-bugAn unexpected behavior, bug, or errorhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22type-bug%22
on Sep 30, 2023https://github.com/python/cpython/issues/110131#event-10516174127
iritkatrielhttps://github.com/iritkatriel
stdlibStandard Library Python modules in the Lib/ directoryhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22stdlib%22
on Nov 26, 2023https://github.com/python/cpython/issues/110131#event-11063913049
https://github.com/hpaulj
hpauljhttps://github.com/hpaulj
on Feb 14, 2024https://github.com/python/cpython/issues/110131#issuecomment-1944604206
serhiy-storchakahttps://github.com/serhiy-storchaka
Argparse issueshttps://github.com/orgs/python/projects/5
on Mar 1, 2024https://github.com/python/cpython/issues/110131#event-14884370198
https://github.com/serhiy-storchaka
serhiy-storchakahttps://github.com/serhiy-storchaka
on Sep 25, 2024https://github.com/python/cpython/issues/110131#issuecomment-2375141278
#84545https://github.com/python/cpython/issues/84545
serhiy-storchakahttps://github.com/serhiy-storchaka
docsDocumentation in the Doc dirhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22docs%22
3.12only security fixeshttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%223.12%22
3.13only security fixeshttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%223.13%22
3.14bugs and security fixeshttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%223.14%22
type-bugAn unexpected behavior, bug, or errorhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22type-bug%22
on Sep 25, 2024https://github.com/python/cpython/issues/110131#event-14405355160
serhiy-storchakahttps://github.com/serhiy-storchaka
Argparse issueshttps://github.com/orgs/python/projects/5
on Oct 11, 2024https://github.com/python/cpython/issues/110131
savannahostrowskihttps://github.com/savannahostrowski
on Nov 5, 2024https://github.com/python/cpython/issues/110131#event-15113915680
savannahostrowskihttps://github.com/savannahostrowski
on Oct 27, 2025https://github.com/python/cpython/issues/110131#event-20513410115
v0ropaevhttps://github.com/v0ropaev
on Sep 25, 2026https://github.com/python/cpython/issues/110131#event-31848222517
pythongh-110131: Drop the test, show a non-empty default in the examplehttps://github.com/v0ropaev/cpython/commit/02246d2c6cba9ce55aaa5eea2c1b54c386baa1b2
pythongh-110131https://github.com/python/cpython/issues/110131
02246d2https://github.com/v0ropaev/cpython/commit/02246d2c6cba9ce55aaa5eea2c1b54c386baa1b2
pythongh-110131: Keep one extend examplehttps://github.com/v0ropaev/cpython/commit/844bb6313a9f0782a5a8aff2d59c31c8d5bcbe24
pythongh-110131https://github.com/python/cpython/issues/110131
844bb63https://github.com/v0ropaev/cpython/commit/844bb6313a9f0782a5a8aff2d59c31c8d5bcbe24
savannahostrowskihttps://github.com/savannahostrowski
on Sep 28, 2026https://github.com/python/cpython/issues/110131#event-32007606556
Merge branch 'main' into pythongh-110131-argparse-append-defaulthttps://github.com/v0ropaev/cpython/commit/0bf408329a46d776082f98fd1b775c3cba4b7ebc
pythongh-110131https://github.com/python/cpython/issues/110131
0bf4083https://github.com/v0ropaev/cpython/commit/0bf408329a46d776082f98fd1b775c3cba4b7ebc
gh-110131: Document how a non-empty default works with append and ext…https://github.com/python/cpython/commit/70bc048e5cc5ae28663381bdc906292b5c5bf334
gh-110131https://github.com/python/cpython/issues/110131
70bc048https://github.com/python/cpython/commit/70bc048e5cc5ae28663381bdc906292b5c5bf334
savannahostrowskihttps://github.com/savannahostrowski
completedhttps://github.com/python/cpython/issues?q=is%3Aissue%20state%3Aclosed%20archived%3Afalse%20reason%3Acompleted
#158155https://github.com/python/cpython/pull/158155
on Sep 28, 2026https://github.com/python/cpython/issues/110131#event-32008319608
Sign up for freehttps://github.com/signup?return_to=https://github.com/python/cpython/issues/110131
Sign in to commenthttps://github.com/login?return_to=https://github.com/python/cpython/issues/110131
3.12only security fixeshttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%223.12%22
3.13only security fixeshttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%223.13%22
3.14bugs and security fixeshttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%223.14%22
docsDocumentation in the Doc dirhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22docs%22
stdlibStandard Library Python modules in the Lib/ directoryhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22stdlib%22
Argparse issueshttps://github.com/orgs/python/projects/5
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.