Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use ==/!= to compare str, bytes, and int literals #327

Merged
merged 1 commit into from
Oct 28, 2019

Conversation

cclauss
Copy link
Contributor

@cclauss cclauss commented Oct 27, 2019

Identity is not the same thing as equality in Python.

Porting to Python 3.8

The compiler now produces a SyntaxWarning when identity checks (is and is not) are used with certain types of literals (e.g. strings, numbers). These can often work by accident in CPython, but are not guaranteed by the language spec. The warning advises users to use equality tests (== and !=) instead. (Contributed by Serhiy Storchaka in bpo-34850.)

flake8 testing of https://github.com/jupyter/kernel_gateway on Python 3.8.0

$ flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics

./kernel_gateway/notebook_http/request_utils.py:68:18: F632 use ==/!= to compare str, bytes, and int literals
    body = '' if body is b'' or body is None else body.decode(encoding='UTF-8')
                 ^
1     F632 use ==/!= to compare str, bytes, and int literals
1

flake8 testing of https://github.com/jupyter/kernel_gateway on Python 3.8.0

$ __flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics__
```
./kernel_gateway/notebook_http/request_utils.py:68:18: F632 use ==/!= to compare str, bytes, and int literals
    body = '' if body is b'' or body is None else body.decode(encoding='UTF-8')
                 ^
1     F632 use ==/!= to compare str, bytes, and int literals
1
```
Copy link
Contributor

@rolweber rolweber left a comment

Choose a reason for hiding this comment

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

lgtm

@rolweber
Copy link
Contributor

Thanks!

@rolweber rolweber merged commit 6c3aa82 into jupyter-server:master Oct 28, 2019
@cclauss cclauss deleted the patch-1 branch October 28, 2019 06:55
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.

2 participants