-
-
Notifications
You must be signed in to change notification settings - Fork 562
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
Remove redundant Python <= 2.6 code #270
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! Some of these files are copied from elsewhere and have been unmaintained for years, but overall, this PR cleans up quite a bit of corners.
benchmark/benchbase.py
Outdated
@@ -11,7 +11,7 @@ def exec_(code, glob): | |||
if sys.version_info[0] >= 3: | |||
exec(code, glob) | |||
else: | |||
exec("exec code in glob") | |||
exec "exec code in glob" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
exec()
is a function in Py3, so this won't work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This only gets called when sys.version_info[0] < 3
, but shall I revert it anyway?
src/lxml/apihelpers.pxi
Outdated
@@ -273,8 +273,7 @@ cdef _iter_attrib(attrib): | |||
# attrib will usually be a plain unordered dict | |||
if type(attrib) is dict: | |||
return sorted(attrib.items()) | |||
elif isinstance(attrib, _Attrib) or ( | |||
OrderedDict is not None and isinstance(attrib, OrderedDict)): | |||
elif isinstance(attrib, _Attrib) or (isinstance(attrib, OrderedDict)): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be simplified to isinstance(attrib, (_Attrib, OrderedDict))
src/lxml/doctestcompare.py
Outdated
diff_parts.append(self.collect_diff(want_doc, got_doc, html, 2)) | ||
diff_parts = ['Expected:', self.format_doc(want_doc, html, 2), | ||
'Got:', self.format_doc(got_doc, html, 2), | ||
'Diff:', self.collect_diff(want_doc, got_doc, html, 2)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't write this code, but I would guess that it was written this way to mimic the way the output is split into lines. I'd rather keep it in a line-by-line split.
src/lxml/etree.pyx
Outdated
@@ -66,10 +66,7 @@ cdef object BytesIO, StringIO | |||
from io import BytesIO, StringIO | |||
|
|||
cdef object OrderedDict = None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The = None
is redundant now (and actually always was).
src/lxml/html/clean.py
Outdated
if avoid_hosts is None: | ||
avoid_hosts = _avoid_hosts | ||
if avoid_classes is None: | ||
avoid_classes = _avoid_classes |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd rather keep all of these (in all functions you changed) as visible and introspectable default arguments. Make them tuples if you prefer (and if that doesn't break anything).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, I'll just revert that commit.
@@ -82,7 +82,7 @@ def test_write_Element_repeatedly(self): | |||
tree = self._parse_file() | |||
self.assertTrue(tree is not None) | |||
self.assertEqual(100, len(tree.getroot())) | |||
self.assertEqual(set(['test']), set(el.tag for el in tree.getroot())) | |||
self.assertEqual({'test'}, set(el.tag for el in tree.getroot())) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use a set comprehension?
"input", "keygen", "link", "meta", "param", | ||
"source", "track", "wbr" | ||
]) | ||
void_elements = {"area", "base", "br", "col", "embed", "hr", "img", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I preferred the previous formatting (i.e. start a new line for the items).
src/lxml/tests/test_io.py
Outdated
return getattr(self._tmpfile, name) | ||
else: | ||
NamedTemporaryFile = tempfile.NamedTemporaryFile | ||
NamedTemporaryFile = tempfile.NamedTemporaryFile |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This shouldn't be a global any more. Instead, the usages in the file should be prefixed with tempfile.
to match the other usages of the module
src/lxml/tests/test_isoschematron.py
Outdated
|
||
schematron = isoschematron.Schematron(schema, store_report=False) | ||
self.assertTrue(schematron(tree_valid), schematron.error_log) | ||
valid = schematron(tree_invalid) | ||
self.assertTrue(not valid) | ||
self.assertTrue(schematron.validation_report is None, | ||
'validation reporting switched off, still: %s' % | ||
(schematron.validation_report)) | ||
schematron.validation_report) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since the indentation is inconsistent between the two changes now, I'd prefer having both at the and of the previous line, right after the %
.
tox.ini
Outdated
@@ -4,7 +4,7 @@ | |||
# and then run "tox" from this directory. | |||
|
|||
[tox] | |||
envlist = py26, py27, py32, py33, py34 | |||
envlist = py27, py33, py34 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
… and py35, py36, py37. Looks like this hasn't been used in a while. :)
This reverts commit 92faebc.
It obviously will not be called because it won't even pass through the Python 3 parser. ;-)
|
Updated! I think I addressed everything, please let me know if I missed something. |
Thanks! |
You're welcome, and thank you for lxml! What do you think about dropping support for Python 3.3? It's also EOL and little used. There probably wouldn't be much, if any, code to remove, but one benefit would be to drop a couple of builds from the CI, and one less thing to worry about. Here's the pip installs for lxml from PyPI for July 2018:
Source: |
Sounds good to me. |
Please see PR #271. |
Support for Python 2.6 was officially removed in 9436948.
This removes some redundant code for Python 2.6 and earlier, and modernises some of the code using PyCharm's code inspections.