code confuses identity and equality (fixed upstream)

Bug #1917318 reported by William Cheng
12
This bug affects 2 people
Affects Status Importance Assigned to Milestone
Debian
Fix Released
Unknown
ansible (Ubuntu)
Invalid
Undecided
Unassigned
python-jmespath (Ubuntu)
Confirmed
Undecided
Unassigned
python-netaddr (Ubuntu)
Confirmed
Undecided
Unassigned

Bug Description

IMPACT:

Python 3.8 has started to emit warnings for code that confuses equality and identity. For more background see https://adamj.eu/tech/2020/01/21/why-does-python-3-8-syntaxwarning-for-is-literal/

While it is just a warning, it is very visible when running ansible on focal for example, to the point of making the output incredibly hard to follow. Furthermore, the indifference between identity and equality might be creating true bugs as discussed in above blog entry. It seems advisable to fix this incorrect code when found.

TEST CASE:

tbd

REGRESSION POTENTIAL:

The current code checks for identity via "is" and and "is not"...

Original report below:
======================
lsb_release -rd
Description: Ubuntu 20.04.2 LTS
Release: 20.04

apt-cache policy ansible
ansible:
  Installed: 2.9.6+dfsg-1
  Candidate: 2.9.6+dfsg-1
  Version table:
 *** 2.9.6+dfsg-1 500
        500 http://tw.archive.ubuntu.com/ubuntu focal/universe amd64 Packages
        500 http://tw.archive.ubuntu.com/ubuntu focal/universe i386 Packages
        100 /var/lib/dpkg/status

Hi, I install ansible have output some log:

Selecting previously unselected package python3-markupsafe.
(Reading database ... 194136 files and directories currently installed.)
Preparing to unpack .../00-python3-markupsafe_1.1.0-1build2_amd64.deb ...
Unpacking python3-markupsafe (1.1.0-1build2) ...
Selecting previously unselected package python3-jinja2.
Preparing to unpack .../01-python3-jinja2_2.10.1-2_all.deb ...
Unpacking python3-jinja2 (2.10.1-2) ...
Selecting previously unselected package python3-dnspython.
Preparing to unpack .../02-python3-dnspython_1.16.0-1build1_all.deb ...
Unpacking python3-dnspython (1.16.0-1build1) ...
Selecting previously unselected package ieee-data.
Preparing to unpack .../03-ieee-data_20180805.1_all.deb ...
Unpacking ieee-data (20180805.1) ...
Selecting previously unselected package python3-netaddr.
Preparing to unpack .../04-python3-netaddr_0.7.19-3_all.deb ...
Unpacking python3-netaddr (0.7.19-3) ...
Selecting previously unselected package ansible.
Preparing to unpack .../05-ansible_2.9.6+dfsg-1_all.deb ...
Unpacking ansible (2.9.6+dfsg-1) ...
Selecting previously unselected package python3-argcomplete.
Preparing to unpack .../06-python3-argcomplete_1.8.1-1.3ubuntu1_all.deb ...
Unpacking python3-argcomplete (1.8.1-1.3ubuntu1) ...
Selecting previously unselected package python3-jmespath.
Preparing to unpack .../07-python3-jmespath_0.9.4-2_all.deb ...
Unpacking python3-jmespath (0.9.4-2) ...
Selecting previously unselected package python3-kerberos.
Preparing to unpack .../08-python3-kerberos_1.1.14-3.1build1_amd64.deb ...
Unpacking python3-kerberos (1.1.14-3.1build1) ...
Selecting previously unselected package python3-lockfile.
Preparing to unpack .../09-python3-lockfile_1%3a0.12.2-2ubuntu2_all.deb ...
Unpacking python3-lockfile (1:0.12.2-2ubuntu2) ...
Selecting previously unselected package python3-libcloud.
Preparing to unpack .../10-python3-libcloud_2.8.0-1_all.deb ...
Unpacking python3-libcloud (2.8.0-1) ...
Selecting previously unselected package python3-ntlm-auth.
Preparing to unpack .../11-python3-ntlm-auth_1.1.0-1_all.deb ...
Unpacking python3-ntlm-auth (1.1.0-1) ...
Selecting previously unselected package python3-requests-kerberos.
Preparing to unpack .../12-python3-requests-kerberos_0.12.0-2_all.deb ...
Unpacking python3-requests-kerberos (0.12.0-2) ...
Selecting previously unselected package python3-requests-ntlm.
Preparing to unpack .../13-python3-requests-ntlm_1.1.0-1_all.deb ...
Unpacking python3-requests-ntlm (1.1.0-1) ...
Selecting previously unselected package python3-selinux.
Preparing to unpack .../14-python3-selinux_3.0-1build2_amd64.deb ...
Unpacking python3-selinux (3.0-1build2) ...
Selecting previously unselected package python3-xmltodict.
Preparing to unpack .../15-python3-xmltodict_0.12.0-1_all.deb ...
Unpacking python3-xmltodict (0.12.0-1) ...
Selecting previously unselected package python3-winrm.
Preparing to unpack .../16-python3-winrm_0.3.0-2_all.deb ...
Unpacking python3-winrm (0.3.0-2) ...
Setting up python3-lockfile (1:0.12.2-2ubuntu2) ...
Setting up python3-ntlm-auth (1.1.0-1) ...
Setting up python3-kerberos (1.1.14-3.1build1) ...
Setting up python3-libcloud (2.8.0-1) ...
Setting up python3-markupsafe (1.1.0-1build2) ...
Setting up python3-xmltodict (0.12.0-1) ...
Setting up python3-jinja2 (2.10.1-2) ...
Setting up python3-jmespath (0.9.4-2) ...
/usr/lib/python3/dist-packages/jmespath/visitor.py:32: SyntaxWarning: "is" with a literal. Did you mean "=="?
  if x is 0 or x is 1:
/usr/lib/python3/dist-packages/jmespath/visitor.py:32: SyntaxWarning: "is" with a literal. Did you mean "=="?
  if x is 0 or x is 1:
/usr/lib/python3/dist-packages/jmespath/visitor.py:34: SyntaxWarning: "is" with a literal. Did you mean "=="?
  elif y is 0 or y is 1:
/usr/lib/python3/dist-packages/jmespath/visitor.py:34: SyntaxWarning: "is" with a literal. Did you mean "=="?
  elif y is 0 or y is 1:
/usr/lib/python3/dist-packages/jmespath/visitor.py:260: SyntaxWarning: "is" with a literal. Did you mean "=="?
  if original_result is 0:
Setting up python3-requests-kerberos (0.12.0-2) ...
Setting up ieee-data (20180805.1) ...
Setting up python3-dnspython (1.16.0-1build1) ...
Setting up python3-selinux (3.0-1build2) ...
Setting up python3-argcomplete (1.8.1-1.3ubuntu1) ...
Setting up python3-requests-ntlm (1.1.0-1) ...
Setting up python3-netaddr (0.7.19-3) ...
/usr/lib/python3/dist-packages/netaddr/strategy/__init__.py:189: SyntaxWarning: "is not" with a literal. Did you mean "!="?
  if word_sep is not '':
Setting up python3-winrm (0.3.0-2) ...
Setting up ansible (2.9.6+dfsg-1) ...
Processing triggers for man-db (2.9.1-1) ...

Changed in ansible (Ubuntu):
status: New → Invalid
Revision history for this message
Rolf Leggewie (r0lf) wrote :

This is indeed a bug. Thank you for reporting. More info at https://adamj.eu/tech/2020/01/21/why-does-python-3-8-syntaxwarning-for-is-literal/

Revision history for this message
Rolf Leggewie (r0lf) wrote :

affected lines

189: /usr/lib/python3/dist-packages/netaddr/strategy/__init__.py
260: /usr/lib/python3/dist-packages/jmespath/visitor.py
34 : /usr/lib/python3/dist-packages/jmespath/visitor.py

Changed in python-jmespath (Ubuntu):
status: New → Confirmed
Changed in python-netaddr (Ubuntu):
status: New → Confirmed
summary: - apt install have ouput some info
+ code confuses identity and equality (upstream issue)
Revision history for this message
Rolf Leggewie (r0lf) wrote : Re: code confuses identity and equality (upstream issue)
tags: added: bionic
tags: added: focal
removed: bionic
tags: added: patch-accepted-upstream
summary: - code confuses identity and equality (upstream issue)
+ code confuses identity and equality (fixed upstream)
Revision history for this message
Rolf Leggewie (r0lf) wrote :

code inspection shows that both packages have already been fixed in hirsute

Revision history for this message
Rolf Leggewie (r0lf) wrote :
Revision history for this message
Rolf Leggewie (r0lf) wrote :
Rolf Leggewie (r0lf)
description: updated
Revision history for this message
Rolf Leggewie (r0lf) wrote :

bugfixed package available from my SRU PPA
https://launchpad.net/~r0lf/+archive/ubuntu/stable/

Changed in debian:
status: Unknown → Fix Released
Rolf Leggewie (r0lf)
description: updated
Rolf Leggewie (r0lf)
description: updated
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.