| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Sorry, something went wrong.
Running
```python
{}.get("a", default="b")
```
gives:
```
{}.get("a", default="b")
~~~~~~^^^^^^^^^^^^^^^^^^
TypeError: dict.get() takes no keyword arguments
```
Interesting. I wonder if that's worth fixing (but I also wonder if this has been brought up before). |
Sorry, something went wrong.
Oh, I didn't see that there is! #124675...where I participated in the discussion 😅 |
Sorry, something went wrong.
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: ...
@overloadand discussion around that at python/typeshed#6694. |
Sorry, something went wrong.
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! |
Sorry, something went wrong.
|
Instead of the change proposed here, a note like the following would better reflect the status quo:
You can pass key= and default= as keyword arguments in PyPy (see online interpreter). |
Sorry, something went wrong.
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. |
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
Running
{}.get("a", default="b")gives:
{}.get("a", default="b") ~~~~~~^^^^^^^^^^^^^^^^^^ TypeError: dict.get() takes no keyword argumentsRelatedly, this means that dict does not implement collections.abc.Mapping which does allow keyword arguments:
cpython/Lib/_collections_abc.py
Line 808 in 6f3c2c8
📚 Documentation preview 📚: https://cpython-previews--128207.org.readthedocs.build/