adriank / ObjectPath

The agile query language for semi-structured data
http://objectpath.org
MIT License
380 stars 93 forks source link

Complience with Python 3.8 SyntaxWarning when comparing with a literal #105

Closed geanceretta closed 7 months ago

geanceretta commented 2 years ago

Python 3.8 introduced a warning for identity vs equality, as explained here: https://adamj.eu/tech/2020/01/21/why-does-python-3-8-syntaxwarning-for-is-literal/

Objectpath 0.6.1 triggers some SyntaxWarning's as: /usr/local/lib/python3.8/site-packages/objectpath-0.6.1-py3.8.egg/objectpath/core/interpreter.py:379: SyntaxWarning: "is" with a literal. Did you mean "=="? if len_node is 1: # empty list /usr/local/lib/python3.8/site-packages/objectpath-0.6.1-py3.8.egg/objectpath/core/interpreter.py:382: SyntaxWarning: "is" with a literal. Did you mean "=="? if len_node is 2: # list - preserved to catch possible event of leaving it as '[' operator /usr/local/lib/python3.8/site-packages/objectpath-0.6.1-py3.8.egg/objectpath/core/interpreter.py:385: SyntaxWarning: "is" with a literal. Did you mean "=="? if len_node is 3: # selector used [] /usr/local/lib/python3.8/site-packages/objectpath-0.6.1-py3.8.egg/objectpath/core/interpreter.py:398: SyntaxWarning: "is" with a literal. Did you mean "=="? if selectorIsTuple and selector[0] is "[": /usr/local/lib/python3.8/site-packages/objectpath-0.6.1-py3.8.egg/objectpath/utils/timeutils.py:39: SyntaxWarning: "is" with a literal. Did you mean "=="? return (years, years is 1 and "rok" or years < 5 and "lata" or "lat") /usr/local/lib/python3.8/site-packages/objectpath-0.6.1-py3.8.egg/objectpath/utils/timeutils.py:41: SyntaxWarning: "is" with a literal. Did you mean "=="? return (years, years is 1 and "year" or "years") /usr/local/lib/python3.8/site-packages/objectpath-0.6.1-py3.8.egg/objectpath/utils/timeutils.py:47: SyntaxWarning: "is" with a literal. Did you mean "=="? months, months is 1 and "miesiąc" or 1 < months < 5 and "miesiące" /usr/local/lib/python3.8/site-packages/objectpath-0.6.1-py3.8.egg/objectpath/utils/timeutils.py:51: SyntaxWarning: "is" with a literal. Did you mean "=="? return (months, months is 1 and "month" or "months") /usr/local/lib/python3.8/site-packages/objectpath-0.6.1-py3.8.egg/objectpath/utils/timeutils.py:57: SyntaxWarning: "is" with a literal. Did you mean "=="? weeks, weeks is 1 and "tydzień" /usr/local/lib/python3.8/site-packages/objectpath-0.6.1-py3.8.egg/objectpath/utils/timeutils.py:61: SyntaxWarning: "is" with a literal. Did you mean "=="? return (weeks, weeks is 1 and "week" or "weeks") /usr/local/lib/python3.8/site-packages/objectpath-0.6.1-py3.8.egg/objectpath/utils/timeutils.py:65: SyntaxWarning: "is" with a literal. Did you mean "=="? return (days, days is 1 and "dzień" or "dni") /usr/local/lib/python3.8/site-packages/objectpath-0.6.1-py3.8.egg/objectpath/utils/timeutils.py:67: SyntaxWarning: "is" with a literal. Did you mean "=="? return (days, days is 1 and "day" or "days") /usr/local/lib/python3.8/site-packages/objectpath-0.6.1-py3.8.egg/objectpath/utils/timeutils.py:75: SyntaxWarning: "is" with a literal. Did you mean "=="? hours, hours is 1 and "godzina" or 1 < hours < 5 and "godziny" /usr/local/lib/python3.8/site-packages/objectpath-0.6.1-py3.8.egg/objectpath/utils/timeutils.py:79: SyntaxWarning: "is" with a literal. Did you mean "=="? return (hours, hours is 1 and "hour" or "hours") /usr/local/lib/python3.8/site-packages/objectpath-0.6.1-py3.8.egg/objectpath/utils/timeutils.py:85: SyntaxWarning: "is" with a literal. Did you mean "=="? minutes, minutes is 1 and "minuta" or 1 < minutes < 5 and "minuty" /usr/local/lib/python3.8/site-packages/objectpath-0.6.1-py3.8.egg/objectpath/utils/timeutils.py:89: SyntaxWarning: "is" with a literal. Did you mean "=="? return (minutes, minutes is 1 and "minute" or "minutes") /usr/local/lib/python3.8/site-packages/objectpath-0.6.1-py3.8.egg/objectpath/utils/timeutils.py:94: SyntaxWarning: "is" with a literal. Did you mean "=="? seconds, seconds is 1 and "sekunda" or 1 < seconds < 5 and "sekundy" /usr/local/lib/python3.8/site-packages/objectpath-0.6.1-py3.8.egg/objectpath/utils/timeutils.py:98: SyntaxWarning: "is" with a literal. Did you mean "=="? return (seconds, seconds is 1 and "second" or "seconds") /usr/local/lib/python3.8/site-packages/objectpath-0.6.1-py3.8.egg/objectpath/utils/timeutils.py:194: SyntaxWarning: "is" with a literal. Did you mean "=="? if l is 1: /usr/local/lib/python3.8/site-packages/objectpath-0.6.1-py3.8.egg/objectpath/utils/timeutils.py:201: SyntaxWarning: "is" with a literal. Did you mean "=="? if l is 2: /usr/local/lib/python3.8/site-packages/objectpath-0.6.1-py3.8.egg/objectpath/utils/json_ext.py:97: SyntaxWarning: "is" with a literal. Did you mean "=="? if length is -1: /usr/local/lib/python3.8/site-packages/objectpath-0.6.1-py3.8.egg/objectpath/utils/json_ext.py:101: SyntaxWarning: "is not" with a literal. Did you mean "!="? if length is not -1 and len(o) > length:

May I submit a replacement for those comparisons?

adriank commented 2 years ago

It is fixed but not uploaded to PyPI. Use the Github version.

Greetings, Adrian Kalbarczyk

https://kalbarczyk.co

On Sat, Aug 13, 2022 at 9:12 PM Gean Michel Ceretta < @.***> wrote:

Python 3.8 introduced a warning for identity vs equality, as explained here: https://adamj.eu/tech/2020/01/21/why-does-python-3-8-syntaxwarning-for-is-literal/

Objectpath 0.6.1 triggers some SyntaxWarning's as: /usr/local/lib/python3.8/site-packages/objectpath-0.6.1-py3.8.egg/objectpath/core/interpreter.py:379: SyntaxWarning: "is" with a literal. Did you mean "=="? if len_node is 1: # empty list /usr/local/lib/python3.8/site-packages/objectpath-0.6.1-py3.8.egg/objectpath/core/interpreter.py:382: SyntaxWarning: "is" with a literal. Did you mean "=="? if len_node is 2: # list - preserved to catch possible event of leaving it as '[' operator /usr/local/lib/python3.8/site-packages/objectpath-0.6.1-py3.8.egg/objectpath/core/interpreter.py:385: SyntaxWarning: "is" with a literal. Did you mean "=="? if len_node is 3: # selector used [] /usr/local/lib/python3.8/site-packages/objectpath-0.6.1-py3.8.egg/objectpath/core/interpreter.py:398: SyntaxWarning: "is" with a literal. Did you mean "=="? if selectorIsTuple and selector[0] is "[": /usr/local/lib/python3.8/site-packages/objectpath-0.6.1-py3.8.egg/objectpath/utils/timeutils.py:39: SyntaxWarning: "is" with a literal. Did you mean "=="? return (years, years is 1 and "rok" or years < 5 and "lata" or "lat") /usr/local/lib/python3.8/site-packages/objectpath-0.6.1-py3.8.egg/objectpath/utils/timeutils.py:41: SyntaxWarning: "is" with a literal. Did you mean "=="? return (years, years is 1 and "year" or "years") /usr/local/lib/python3.8/site-packages/objectpath-0.6.1-py3.8.egg/objectpath/utils/timeutils.py:47: SyntaxWarning: "is" with a literal. Did you mean "=="? months, months is 1 and "miesiąc" or 1 < months < 5 and "miesiące" /usr/local/lib/python3.8/site-packages/objectpath-0.6.1-py3.8.egg/objectpath/utils/timeutils.py:51: SyntaxWarning: "is" with a literal. Did you mean "=="? return (months, months is 1 and "month" or "months") /usr/local/lib/python3.8/site-packages/objectpath-0.6.1-py3.8.egg/objectpath/utils/timeutils.py:57: SyntaxWarning: "is" with a literal. Did you mean "=="? weeks, weeks is 1 and "tydzień" /usr/local/lib/python3.8/site-packages/objectpath-0.6.1-py3.8.egg/objectpath/utils/timeutils.py:61: SyntaxWarning: "is" with a literal. Did you mean "=="? return (weeks, weeks is 1 and "week" or "weeks") /usr/local/lib/python3.8/site-packages/objectpath-0.6.1-py3.8.egg/objectpath/utils/timeutils.py:65: SyntaxWarning: "is" with a literal. Did you mean "=="? return (days, days is 1 and "dzień" or "dni") /usr/local/lib/python3.8/site-packages/objectpath-0.6.1-py3.8.egg/objectpath/utils/timeutils.py:67: SyntaxWarning: "is" with a literal. Did you mean "=="? return (days, days is 1 and "day" or "days") /usr/local/lib/python3.8/site-packages/objectpath-0.6.1-py3.8.egg/objectpath/utils/timeutils.py:75: SyntaxWarning: "is" with a literal. Did you mean "=="? hours, hours is 1 and "godzina" or 1 < hours < 5 and "godziny" /usr/local/lib/python3.8/site-packages/objectpath-0.6.1-py3.8.egg/objectpath/utils/timeutils.py:79: SyntaxWarning: "is" with a literal. Did you mean "=="? return (hours, hours is 1 and "hour" or "hours") /usr/local/lib/python3.8/site-packages/objectpath-0.6.1-py3.8.egg/objectpath/utils/timeutils.py:85: SyntaxWarning: "is" with a literal. Did you mean "=="? minutes, minutes is 1 and "minuta" or 1 < minutes < 5 and "minuty" /usr/local/lib/python3.8/site-packages/objectpath-0.6.1-py3.8.egg/objectpath/utils/timeutils.py:89: SyntaxWarning: "is" with a literal. Did you mean "=="? return (minutes, minutes is 1 and "minute" or "minutes") /usr/local/lib/python3.8/site-packages/objectpath-0.6.1-py3.8.egg/objectpath/utils/timeutils.py:94: SyntaxWarning: "is" with a literal. Did you mean "=="? seconds, seconds is 1 and "sekunda" or 1 < seconds < 5 and "sekundy" /usr/local/lib/python3.8/site-packages/objectpath-0.6.1-py3.8.egg/objectpath/utils/timeutils.py:98: SyntaxWarning: "is" with a literal. Did you mean "=="? return (seconds, seconds is 1 and "second" or "seconds") /usr/local/lib/python3.8/site-packages/objectpath-0.6.1-py3.8.egg/objectpath/utils/timeutils.py:194: SyntaxWarning: "is" with a literal. Did you mean "=="? if l is 1: /usr/local/lib/python3.8/site-packages/objectpath-0.6.1-py3.8.egg/objectpath/utils/timeutils.py:201: SyntaxWarning: "is" with a literal. Did you mean "=="? if l is 2: /usr/local/lib/python3.8/site-packages/objectpath-0.6.1-py3.8.egg/objectpath/utils/json_ext.py:97: SyntaxWarning: "is" with a literal. Did you mean "=="? if length is -1: /usr/local/lib/python3.8/site-packages/objectpath-0.6.1-py3.8.egg/objectpath/utils/json_ext.py:101: SyntaxWarning: "is not" with a literal. Did you mean "!="? if length is not -1 and len(o) > length:

May I submit a replacement for those comparisons?

— Reply to this email directly, view it on GitHub https://github.com/adriank/ObjectPath/issues/105, or unsubscribe https://github.com/notifications/unsubscribe-auth/AABLE4RP6XK3GY6IMPNDYUDVY7XP7ANCNFSM56OSI2HQ . You are receiving this because you are subscribed to this thread.Message ID: @.***>