GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Document that dict.get takes no keyword arguments by adamtheturtle · Pull Request #128207 · python/cpython

Conversation

@adamtheturtle

@adamtheturtle adamtheturtle commented Dec 23, 2024 •
edited by github-actions Bot
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

Running

{}.get("a", default="b")

gives:

    {}.get("a", default="b")
    ~~~~~~^^^^^^^^^^^^^^^^^^
TypeError: dict.get() takes no keyword arguments

Relatedly, this means that dict does not implement collections.abc.Mapping which does allow keyword arguments:

cpython/Lib/_collections_abc.py

Line 808 in 6f3c2c8

def get(self, key, default=None):


📚 Documentation preview 📚: https://cpython-previews--128207.org.readthedocs.build/

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

jibal reacted with heart emoji
All reactions
  • ❤️ 1 reaction
@adamtheturtle
Document that dict.get takes no keyword arguments
3115cb1
Running

```python
{}.get("a", default="b")
```

gives:

```
    {}.get("a", default="b")
    ~~~~~~^^^^^^^^^^^^^^^^^^
TypeError: dict.get() takes no keyword arguments
```
@bedevere-app bedevere-app Bot added docs Documentation in the Doc dir skip news awaiting review labels Dec 23, 2024
@ZeroIntensity

ZeroIntensity commented Dec 24, 2024

Copy link
Copy Markdown
Member

Relatedly, this means that dict does not implement collections.abc.Mapping which does allow keyword arguments:

Interesting. I wonder if that's worth fixing (but I also wonder if this has been brought up before).

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@adamtheturtle adamtheturtle mentioned this pull request Dec 24, 2024
Allow default keyword argument in dict.get() method #124675
Closed
@ZeroIntensity

ZeroIntensity commented Dec 24, 2024

Copy link
Copy Markdown
Member

but I also wonder if this has been brought up before

Oh, I didn't see that there is! #124675...where I participated in the discussion 😅

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@adamtheturtle

adamtheturtle commented Dec 24, 2024

Copy link
Copy Markdown
Contributor Author

Interesting. I wonder if that's worth fixing (but I also wonder if this has been brought up before).

I would like for it to be fixed, and I have commented on a related issue (#124675).

As for "brought up before" - I'm not sure here, but I found this comment in typeshed:

    # Positional-only in dict, but not in MutableMapping
    @overload  # type: ignore[override]
    def get(self, key: _KT, /) -> _VT | None: ...
    @overload

https://github.com/python/typeshed/blob/17408ee5381f866c100f5003119a7a1bf050b839/stdlib/builtins.pyi#L1125C1-L1128C14

and discussion around that at python/typeshed#6694.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@adamtheturtle

adamtheturtle commented Dec 24, 2024

Copy link
Copy Markdown
Contributor Author

Oh, I didn't see that there is! https://github.com/python/cpython/issues/124675...where I participated in the discussion 😅

FWIW when you asked I pasted my issue text into ChatGPT and asked "I want to write up this bug for CPython. Has any duplicate issue been brought up before?". It found me that issue!

ZeroIntensity and jibal reacted with rocket emoji
All reactions
  • 🚀 2 reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@adamtheturtle adamtheturtle mentioned this pull request Dec 24, 2024
gh-131885: Document that dict.setdefault takes no keyword arguments #128208
Merged
@picnixz picnixz added the skip issue label Dec 24, 2024
@joooeey

joooeey commented Jan 7, 2025

Copy link
Copy Markdown

Instead of the change proposed here, a note like the following would better reflect the status quo:

CPython implementation detail: All arguments to this method are positional-only.

You can pass key= and default= as keyword arguments in PyPy (see online interpreter).

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@ZeroIntensity

ZeroIntensity commented Mar 25, 2025

Copy link
Copy Markdown
Member

You can pass key= and default= as keyword arguments in PyPy (see online interpreter).

That's arguably a PyPy implementation detail :)

I'm going to close this in favor of #128208, which documents this for setdefault as well. Based on the aforementioned issue, changing the behavior is still on the table, but only for 3.14, so documenting this for bugfix versions is a good first step.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@ZeroIntensity ZeroIntensity closed this Mar 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

awaiting review docs Documentation in the Doc dir skip issue skip news

Projects

Docs PRs
Status: Todo

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

4 participants

@adamtheturtle @ZeroIntensity @joooeey @picnixz
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.