adriank / ObjectPath

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

fix map and filter check on python 2 and 3. #93

Open truebit opened 4 years ago

truebit commented 4 years ago

NameError for map and fitler would only occur in python 1. Python 2 and 3 both got these two keywords.

And type(map(string.lower, 'ABC')) is map is not true in Python 2, but true in Python 3. So I got a version check to add map and filter.

coveralls commented 4 years ago

Coverage Status

Coverage increased (+0.1%) to 89.214% when pulling 4f13d3fba79d46cfdac5974a6eed71712a4a7ac5 on truebit:master into f240821fa197ef5cd04f189c776ae356813abb2b on adriank:master.

adriank commented 4 years ago

Thanks for the PR.

What problem does it solve? From what I remember, try..catch was a little bit faster and made the code work on Python 2 and 3, while other solutions didn't. I wonder if after change this would still work on PyPy or Python 3.3 for example.

truebit commented 4 years ago

This PR fixes #91 tests failure on python 2.

As I mentioned, map and filter cannot be differed by try...catch, as they both exist in python 2 and 3. sys.version_info was introduced in python2.0. I changed access of named tuple attributes to list index to make it working in >=python2.0