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

Appearance settings

bpo-33461: Emit DeprecationWarning when json.loads(encoding=...) is used#6762

Merged
methane merged 5 commits into
python:masterpython/cpython:masterfrom
Carreau:json-loads-deprecatedCarreau/cpython:json-loads-deprecatedCopy head branch name to clipboard
Apr 9, 2019
Merged

bpo-33461: Emit DeprecationWarning when json.loads(encoding=...) is used#6762
methane merged 5 commits into
python:masterpython/cpython:masterfrom
Carreau:json-loads-deprecatedCarreau/cpython:json-loads-deprecatedCopy head branch name to clipboard

Conversation

@Carreau

@Carreau Carreau commented May 11, 2018

Copy link
Copy Markdown
Contributor

I also move in the docs the encoding=... keyword to the end of the
signature, as it is kw only. Having the first argument in the doc being
the deprecated one does not seem to be the most efficient way to make
people forget about it.

This does not, of course emit warnings if you pass None explicitly,
this could be further refined by using a sentinel value, but I'm unsure
this would be useful.

https://bugs.python.org/issue33461

Comment thread Lib/json/__init__.py Outdated
Comment thread Lib/json/__init__.py Outdated
Comment thread Lib/json/__init__.py Outdated
@Carreau Carreau force-pushed the json-loads-deprecated branch from 273b316 to 505d680 Compare May 11, 2018 15:50
@Carreau

Carreau commented May 12, 2018

Copy link
Copy Markdown
Contributor Author

Would you mind restarting the travis build ? The errors seem to be unrelated from the code changes ?

Thanks.

@ned-deily

Copy link
Copy Markdown
Member

The docs check part of the CI build:

make check suspicious html SPHINXOPTS="-q -W -j4"

did fail with an error:

python3 tools/rstlint.py -i tools -i ./venv -i README.rst
[2] library/json.rst:278: default role used
1 problem with severity 2 found.

It looks like

`encoding` keyword

should be

*encoding* keyword

@serhiy-storchaka

Copy link
Copy Markdown
Member

I suggest to just remove this parameter. Seems it should be removed from loads() in 3.1 as it was removed from other functions.

Comment thread Lib/json/__init__.py Outdated
import warnings
warnings.warn(
"passing 'encoding' as a keyword argument is deprecated since"
" Python 3.1 and will be ignored.", DeprecationWarning,

@methane methane Apr 8, 2019

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
" Python 3.1 and will be ignored.", DeprecationWarning,
" Python 3.1 and will be removed in Python 3.9.", DeprecationWarning,

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've done both, as "is ignored" is a current fact. "Deprecated" is not enough to know what the current behavior is. It could be deprecated but still having effect.

Comment thread Lib/json/__init__.py Outdated
f'not {s.__class__.__name__}')
s = s.decode(detect_encoding(s), 'surrogatepass')

if encoding is not _sentinel:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about detecting encoding with kw?

Remove encoding in arguments and:

if 'encoding' in kw:
    del kw['encoding']
    # raise warning

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's actually way better indeed.

…sed.

I also remove the `encoding` keyword from the docs docs.
@Carreau Carreau force-pushed the json-loads-deprecated branch from 73bc3b5 to 06623b5 Compare April 8, 2019 20:48
@Carreau

Carreau commented Apr 8, 2019

Copy link
Copy Markdown
Contributor Author

Updated. Thanks @methane for the review.

Comment thread Doc/library/json.rst Outdated
:exc:`JSONDecodeError` will be raised.

.. deprecated:: 3.1
The *encoding* keyword argument has been deprecated and will be ignored.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"will be ignored" is wrong.
But "deprecated" and "ignored" are described above already. How about simple notation?

.. deprecated-removed:: 3.1 3.9
    *encoding* keyword argument.

Comment thread Lib/json/__init__.py Outdated
import warnings
warnings.warn(
"passing 'encoding' as a keyword argument is deprecated since"
" Python 3.1, is ignored and will be removed in Python 3.9.",

@methane methane Apr 9, 2019

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"as a keyword argument" looks confusing. ("Does it supported as positional argument?")

"'encoding' is ignored and deprecated. It will be removed in Python 3.9".

Additionally, del kw['encoding'] is required. Otherwise, JSONDecoder(..., **kw) will fail.

Comment thread Lib/json/__init__.py Outdated
Co-Authored-By: Carreau <bussonniermatthias@gmail.com>
@Carreau

Carreau commented Apr 9, 2019

Copy link
Copy Markdown
Contributor Author

updated according to your comments.

@Carreau Carreau force-pushed the json-loads-deprecated branch from 06c2c24 to 0ccae85 Compare April 9, 2019 01:04
@methane methane merged commit a8abe09 into python:master Apr 9, 2019
@Carreau Carreau deleted the json-loads-deprecated branch April 9, 2019 14:54
@Carreau

Carreau commented Apr 9, 2019

Copy link
Copy Markdown
Contributor Author

Thanks !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants

Morty Proxy This is a proxified and sanitized view of the page, visit original site.