PyAr / OpenLex

Software para el manejo de estudios jurídicos y oficinas judiciales

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Python3 compatibility

eamanu opened this issue · comments

After a quick search in the code using the next flake8 command: flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics I didn't follow any python3 issue. So, in my opinion openlex might be compatible with py3.

BTW I follow the next issues:

➜  OpenLex git:(master) flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics | grep F632 
./modules/html2text.py:181:12: F632 use ==/!= to compare constant literals (str, bytes, int, float, tuple)
./modules/html2text.py:181:29: F632 use ==/!= to compare constant literals (str, bytes, int, float, tuple)
./modules/html2text.py:182:20: F632 use ==/!= to compare constant literals (str, bytes, int, float, tuple)
3     F632 use ==/!= to compare constant literals (str, bytes, int, float, tuple)

And

➜  OpenLex git:(master) flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics | grep E999
./documents/pyDoctor.py:46:15: E999 SyntaxError: invalid syntax
1     E999 SyntaxError: invalid syntax

@matiasdemarchi can you fixed it?

cc: @marian-vignau

Yes, I think i can fix it. Thanks for the suggestion!

In the case of the Aaron Swartz's program html2text.py, the issue that your command is pointing to, has the following lines:

def onlywhite(line):
"""Return true if the line does only consist of whitespace characters."""
for c in line:
if c is not ' ' and c is not ' ':
return c is ' '
return line

My question is: "is not" and "is", are the same thing that == and != in Python 3? In that case, I wouldn't need to change it.

They aren't the same.

The is operator will return True if the variable is pointing to the same object
And == will compare the value itself.

for instance (I'm on py3.9), using is:

>>> a = "hello world"
>>> a is "hello world"
<stdin>:1: SyntaxWarning: "is" with a literal. Did you mean "=="?
False
>>> 

But if we compare the value equality,

>>> a == "hello world"
True
>>> 

Looking on upstream [0], that lines was not changed, so, I would like to hear the opinion of
@marian-vignau about what to do with this SyntaxWarning.


BTW: seems that exist a newer fork of html2text https://github.com/Alir3z4/html2text/

[0] https://github.com/aaronsw/html2text/blob/master/html2text.py#L92