René's URL Explorer Experiment


Title: Allow `default` keyword argument in dict.get() method · Issue #124675 · python/cpython · GitHub

Open Graph Title: Allow `default` keyword argument in dict.get() method · Issue #124675 · python/cpython

X Title: Allow `default` keyword argument in dict.get() method · Issue #124675 · python/cpython

Description: Feature or enhancement Proposal: Background The dict.get() method is a commonly used feature in Python for retrieving values from dictionaries with a fallback option. Currently, it accepts positional arguments for the key and default val...

Open Graph Description: Feature or enhancement Proposal: Background The dict.get() method is a commonly used feature in Python for retrieving values from dictionaries with a fallback option. Currently, it accepts position...

X Description: Feature or enhancement Proposal: Background The dict.get() method is a commonly used feature in Python for retrieving values from dictionaries with a fallback option. Currently, it accepts position...

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

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Allow `default` keyword argument in dict.get() method","articleBody":"# Feature or enhancement\n\n### Proposal:\n\n## Background\n\nThe `dict.get()` method is a commonly used feature in Python for retrieving values from dictionaries with a fallback option. Currently, it accepts positional arguments for the key and default value. However, allowing a keyword argument for the default value could enhance code readability and align with Python's philosophy of explicit naming.\n\n## Current Behavior\n\nConsider the following code:\n\n```python\nmy_dict = {\"a\": 1, \"b\": 2, \"c\": 3}\nprint(my_dict.get(\"b\", \"Not found\"))\n```\n\nThis works as expected. However, when attempting to use a keyword argument:\n\n```python\nprint(my_dict.get(\"b\", default=\"Not found\"))\n```\n\nIt raises a `TypeError`:\n\n```\nTraceback (most recent call last):\n  File \"/path/to/script.py\", line 3, in \u003cmodule>\n    print(my_dict.get(\"b\", default=\"Not found\"))\nTypeError: dict.get() takes no keyword arguments\n```\n\n## Proposed Enhancement\n\nAllow the use of the `default` keyword argument in the `dict.get()` method. This would make the code more explicit and easier to read, especially in complex expressions or when the default value is a long expression.\n\nProposed syntax:\n\n```python\nmy_dict.get(\"key\", default=\"default_value\")\n```\n\n## Rationale\n\n1. **Readability**: This change aligns with PEP 20 (The Zen of Python), specifically the principle \"Explicit is better than implicit.\" Using a keyword argument makes the intention clearer, especially when the default value is complex or when the method call is part of a larger expression.\n\n2. **Consistency**: Many Python built-in functions and methods allow both positional and keyword arguments for optional parameters (e.g., `sorted(iterable, key=None, reverse=False)`). This change would bring `dict.get()` in line with this common pattern.\n\n3. **Backwards Compatibility**: This change would be backwards compatible, as it only adds functionality without altering existing behavior.\n\n4. **Code Style**: It adheres to PEP 8 guidelines for function calls, allowing for more readable code when line length is a concern.\n\n## Implementation Considerations\n\n- The current positional argument for the default value should still be supported for backwards compatibility.\n- The keyword argument should take precedence if both are provided, with a potential deprecation warning for using both simultaneously.\n\n## Conclusion\n\nIntroducing a `default` keyword argument to `dict.get()` would improve code readability and align with Python's design principles. It represents a small but meaningful enhancement to one of Python's most frequently used methods.\n\n### Has this already been discussed elsewhere?\n\nThis is a minor feature, which does not need previous discussion elsewhere\n\n### Links to previous discussion of this feature:\n\n_No response_","author":{"url":"https://github.com/yuriishizawa","@type":"Person","name":"yuriishizawa"},"datePublished":"2024-09-27T14:51:48Z","url":"https://github.com/python/cpython/issues/124675"}

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:8c15f4c5-b3a3-afd9-6d59-db32bbcf36c7
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idB2E4:197995:289E1DF:3742D96:6B004793
html-safe-nonce46e5b248a253a1a6057ee6516db9a356260b4b975546cd61e10ae0c852460369
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCMkU0OjE5Nzk5NToyODlFMURGOjM3NDJEOTY6NkIwMDQ3OTMiLCJ2aXNpdG9yX2lkIjoiNzI5OTExNTU5MjEyMjkxMDYxMSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9
visitor-hmac5c7182ba8edb1d6a00f2d065aec09fd71ac789107d4ed605b1dd31af74c9d521
hovercard-subject-tagissue:2553132556
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/124675/issue_layout
twitter:imagehttps://opengraph.githubassets.com/53088a9365977cb490fb343d6769989bc59f3659aecad22ffa5e5999d8fadf84/python/cpython/issues/124675
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/53088a9365977cb490fb343d6769989bc59f3659aecad22ffa5e5999d8fadf84/python/cpython/issues/124675
og:image:altFeature or enhancement Proposal: Background The dict.get() method is a commonly used feature in Python for retrieving values from dictionaries with a fallback option. Currently, it accepts position...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernameyuriishizawa
hostnamegithub.com
expected-hostnamegithub.com
None7d0829bbde9e48b2486cb5dd6d147896eb01d32134627091f818958a935ef3f0
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
releasef3f3a43ca095cdea3abbb394112e971f9fdb94fa
ui-targetfull
theme-color#1e2327
color-schemelight dark
react-app-nameissues

Links:

Skip to contenthttps://github.com/python/cpython/issues/124675#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fissues%2F124675
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%2F124675
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/124675
Reloadhttps://github.com/python/cpython/issues/124675
Reloadhttps://github.com/python/cpython/issues/124675
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/124675
New issuehttps://github.com/login?return_to=https://github.com/python/cpython/issues/124675
Allow default keyword argument in dict.get() methodhttps://github.com/python/cpython/issues/124675#top
interpreter-core(Objects, Python, Grammar, and Parser dirs)https://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22interpreter-core%22
type-featureA feature request or enhancementhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22type-feature%22
https://github.com/yuriishizawa
yuriishizawahttps://github.com/yuriishizawa
on Sep 27, 2024https://github.com/python/cpython/issues/124675#issue-2553132556
yuriishizawahttps://github.com/yuriishizawa
type-featureA feature request or enhancementhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22type-feature%22
on Sep 27, 2024https://github.com/python/cpython/issues/124675#event-14432439187
https://github.com/picnixz
picnixzhttps://github.com/picnixz
on Sep 27, 2024https://github.com/python/cpython/issues/124675#issuecomment-2379613035
https://discuss.python.org/c/ideas/6https://discuss.python.org/c/ideas/6
picnixzhttps://github.com/picnixz
pendingThe issue will be closed if no feedback is providedhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22pending%22
on Sep 27, 2024https://github.com/python/cpython/issues/124675#event-14433357506
https://github.com/rruuaanng
rruuaannghttps://github.com/rruuaanng
on Sep 28, 2024https://github.com/python/cpython/issues/124675#issuecomment-2380549716
@picnixzhttps://github.com/picnixz
https://github.com/rruuaanng
rruuaannghttps://github.com/rruuaanng
on Sep 28, 2024https://github.com/python/cpython/issues/124675#issuecomment-2380552499
https://github.com/ZeroIntensity
ZeroIntensityhttps://github.com/ZeroIntensity
on Sep 29, 2024https://github.com/python/cpython/issues/124675#issuecomment-2381414557
@yuriishizawahttps://github.com/yuriishizawa
DPOhttps://discuss.python.org/
ZeroIntensityhttps://github.com/ZeroIntensity
not plannedhttps://github.com/python/cpython/issues?q=is%3Aissue%20state%3Aclosed%20archived%3Afalse%20reason%3Anot-planned
on Sep 29, 2024https://github.com/python/cpython/issues/124675#event-14445669535
ZeroIntensityhttps://github.com/ZeroIntensity
pendingThe issue will be closed if no feedback is providedhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22pending%22
on Sep 29, 2024https://github.com/python/cpython/issues/124675#event-14445669881
https://github.com/joooeey
joooeeyhttps://github.com/joooeey
on Oct 24, 2024https://github.com/python/cpython/issues/124675#issuecomment-2435629416
Python documentationhttps://docs.python.org/3/library/stdtypes.html#dict.get
https://github.com/ZeroIntensity
ZeroIntensityhttps://github.com/ZeroIntensity
on Oct 24, 2024https://github.com/python/cpython/issues/124675#issuecomment-2435643011
https://github.com/joooeey
joooeeyhttps://github.com/joooeey
on Oct 28, 2024https://github.com/python/cpython/issues/124675#issuecomment-2440995814
slash in the function signaturehttps://docs.python.org/3/faq/programming.html#id26
fasthttp://speed.pypy.org/
complianthttps://pypy.org/compat.html
Pythonhttp://python.org/
Check it out in the online interpreterhttps://ideone.com/uJYOHA
spec on python.orghttps://docs.python.org/3/library/stdtypes.html#dict.get
see online interpreterhttps://www.programiz.com/online-compiler/4wQvBre2NTXEU
as per the docshttps://devguide.python.org/developer-workflow/lang-changes/
https://github.com/ZeroIntensity
ZeroIntensityhttps://github.com/ZeroIntensity
on Oct 28, 2024https://github.com/python/cpython/issues/124675#issuecomment-2441077451
discuss.python.orghttps://discuss.python.org/
https://github.com/joooeey
joooeeyhttps://github.com/joooeey
on Oct 28, 2024https://github.com/python/cpython/issues/124675#issuecomment-2441243205
PEP 457https://peps.python.org/pep-0457/
PEP 570https://peps.python.org/pep-0570/
https://github.com/ZeroIntensity
ZeroIntensityhttps://github.com/ZeroIntensity
on Oct 29, 2024https://github.com/python/cpython/issues/124675#issuecomment-2444702619
https://github.com/joooeey
joooeeyhttps://github.com/joooeey
on Nov 4, 2024https://github.com/python/cpython/issues/124675#issuecomment-2454046974
PEP 457https://peps.python.org/pep-0457/
https://github.com/adamtheturtle
adamtheturtlehttps://github.com/adamtheturtle
on Dec 24, 2024https://github.com/python/cpython/issues/124675#issuecomment-2560672965
#128207https://github.com/python/cpython/pull/128207
cpython/Lib/_collections_abc.pyhttps://github.com/python/cpython/blob/6f3c2c8d04e4981bdc3aec54e14236119c1aedcc/Lib/_collections_abc.py#L808
6f3c2c8https://github.com/python/cpython/commit/6f3c2c8d04e4981bdc3aec54e14236119c1aedcc
PEP 457https://peps.python.org/pep-0457/
https://github.com/ZeroIntensity
ZeroIntensityhttps://github.com/ZeroIntensity
on Dec 24, 2024https://github.com/python/cpython/issues/124675#issuecomment-2561225635
gh-128207https://github.com/python/cpython/pull/128207
@JelleZijlstrahttps://github.com/JelleZijlstra
ZeroIntensityhttps://github.com/ZeroIntensity
on Dec 24, 2024https://github.com/python/cpython/issues/124675#event-15757492243
https://github.com/picnixz
picnixzhttps://github.com/picnixz
on Dec 24, 2024https://github.com/python/cpython/issues/124675#issuecomment-2561238643
picnixzhttps://github.com/picnixz
interpreter-core(Objects, Python, Grammar, and Parser dirs)https://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22interpreter-core%22
on Dec 24, 2024https://github.com/python/cpython/issues/124675#event-15757580158
https://github.com/JelleZijlstra
JelleZijlstrahttps://github.com/JelleZijlstra
on Dec 24, 2024https://github.com/python/cpython/issues/124675#issuecomment-2561246347
https://github.com/joooeey
joooeeyhttps://github.com/joooeey
on Jan 7, 2025https://github.com/python/cpython/issues/124675#issuecomment-2574942000
https://github.com/joooeey
joooeeyhttps://github.com/joooeey
on Jan 7, 2025https://github.com/python/cpython/issues/124675#issuecomment-2574972061
https://github.com/abcwarbot
abcwarbothttps://github.com/abcwarbot
on Sep 16, 2025https://github.com/python/cpython/issues/124675#issuecomment-3298732717
https://github.com/picnixz
picnixzhttps://github.com/picnixz
on Sep 16, 2025https://github.com/python/cpython/issues/124675#issuecomment-3298750335
https://github.com/abcwarbot
abcwarbothttps://github.com/abcwarbot
on Sep 16, 2025https://github.com/python/cpython/issues/124675#issuecomment-3298763138
https://github.com/picnixz
picnixzhttps://github.com/picnixz
on Sep 16, 2025https://github.com/python/cpython/issues/124675#issuecomment-3298863402
https://discuss.python.org/c/ideas/6https://discuss.python.org/c/ideas/6
picnixzhttps://github.com/picnixz
not plannedhttps://github.com/python/cpython/issues?q=is%3Aissue%20state%3Aclosed%20archived%3Afalse%20reason%3Anot-planned
on Sep 16, 2025https://github.com/python/cpython/issues/124675#event-19727414187
Sign up for freehttps://github.com/signup?return_to=https://github.com/python/cpython/issues/124675
Sign in to commenthttps://github.com/login?return_to=https://github.com/python/cpython/issues/124675
interpreter-core(Objects, Python, Grammar, and Parser dirs)https://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22interpreter-core%22
type-featureA feature request or enhancementhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22type-feature%22
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.