Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Document that dict.get takes no keyword arguments#128207

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Closed
adamtheturtle wants to merge1 commit intopython:mainfromadamtheturtle:patch-1

Conversation

adamtheturtle
Copy link
Contributor

@adamtheturtleadamtheturtle commentedDec 23, 2024
edited by github-actionsbot
Loading

Running

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

gives:

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

Relatedly, this means thatdict does not implementcollections.abc.Mapping which does allow keyword arguments:

defget(self,key,default=None):


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

jibal reacted with heart emoji
Running```python{}.get("a", default="b")```gives:```    {}.get("a", default="b")    ~~~~~~^^^^^^^^^^^^^^^^^^TypeError: dict.get() takes no keyword arguments```
@bedevere-appbedevere-appbot added docsDocumentation in the Doc dir skip news awaiting review labelsDec 23, 2024
@ZeroIntensity
Copy link
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).

@ZeroIntensity
Copy link
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 😅

@adamtheturtle
Copy link
ContributorAuthor

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 intypeshed:

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

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

and discussion around that atpython/typeshed#6694.

@adamtheturtle
Copy link
ContributorAuthor

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

@joooeey
Copy link

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 passkey= anddefault= as keyword arguments in PyPy (see online interpreter).

@ZeroIntensity
Copy link
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 forsetdefault 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.

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers
No reviews
Assignees
No one assigned
Labels
awaiting reviewdocsDocumentation in the Doc dirskip issueskip news
Projects
Status: Todo
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

4 participants
@adamtheturtle@ZeroIntensity@joooeey@picnixz

[8]ページ先頭

©2009-2025 Movatter.jp