Skip to content
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

Merged
merged 23 commits into from Aug 26, 2018
Merged

Remove redundant Python <= 2.6 code #270

merged 23 commits into from Aug 26, 2018

Conversation

@hugovk
Copy link
Contributor

@hugovk hugovk commented Aug 26, 2018

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.

Copy link
Member

@scoder scoder left a comment

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.

@@ -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"
Copy link
Member

@scoder scoder Aug 26, 2018

exec() is a function in Py3, so this won't work.

Copy link
Contributor Author

@hugovk hugovk Aug 26, 2018

This only gets called when sys.version_info[0] < 3, but shall I revert it anyway?

@@ -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)):
Copy link
Member

@scoder scoder Aug 26, 2018

This can be simplified to isinstance(attrib, (_Attrib, OrderedDict))

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)]
Copy link
Member

@scoder scoder Aug 26, 2018

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.

@@ -66,10 +66,7 @@ cdef object BytesIO, StringIO
from io import BytesIO, StringIO

cdef object OrderedDict = None
Copy link
Member

@scoder scoder Aug 26, 2018

The = None is redundant now (and actually always was).

if avoid_hosts is None:
avoid_hosts = _avoid_hosts
if avoid_classes is None:
avoid_classes = _avoid_classes
Copy link
Member

@scoder scoder Aug 26, 2018

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).

Copy link
Contributor Author

@hugovk hugovk Aug 26, 2018

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()))
Copy link
Member

@scoder scoder Aug 26, 2018

Use a set comprehension?

"input", "keygen", "link", "meta", "param",
"source", "track", "wbr"
])
void_elements = {"area", "base", "br", "col", "embed", "hr", "img",
Copy link
Member

@scoder scoder Aug 26, 2018

I preferred the previous formatting (i.e. start a new line for the items).

return getattr(self._tmpfile, name)
else:
NamedTemporaryFile = tempfile.NamedTemporaryFile
NamedTemporaryFile = tempfile.NamedTemporaryFile
Copy link
Member

@scoder scoder Aug 26, 2018

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


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)
Copy link
Member

@scoder scoder Aug 26, 2018

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
Copy link
Member

@scoder scoder Aug 26, 2018

… and py35, py36, py37. Looks like this hasn't been used in a while. :)

@scoder
Copy link
Member

@scoder scoder commented Aug 26, 2018

@hugovk
Copy link
Contributor Author

@hugovk hugovk commented Aug 26, 2018

Updated! I think I addressed everything, please let me know if I missed something.

@scoder
Copy link
Member

@scoder scoder commented Aug 26, 2018

Thanks!

@scoder scoder merged commit eb4d8c4 into lxml:master Aug 26, 2018
1 check passed
@hugovk hugovk deleted the rm-2.6 branch Aug 26, 2018
@hugovk
Copy link
Contributor Author

@hugovk hugovk commented Aug 26, 2018

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:

python_version percent download_count
2.7 59.75% 637,606
3.6 22.04% 235,237
3.5 11.17% 119,194
3.4 4.08% 43,500
3.7 2.79% 29,729
2.6 0.10% 1,061
3.3 0.05% 553
3.8 0.01% 160
3.2 0.00% 41
None 0.00% 5
Total 1,067,086

Source: pypinfo --start-date 2018-07-01 --end-date 2018-07-31 --percent --markdown lxml pyversion

@scoder
Copy link
Member

@scoder scoder commented Aug 26, 2018

Sounds good to me.

@hugovk
Copy link
Contributor Author

@hugovk hugovk commented Aug 26, 2018

Please see PR #271.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants