D12251: check-py3-compat: drop support for Python 2
indygreg (Gregory Szorc)
phabricator at mercurial-scm.org
Wed Mar 2 00:44:03 UTC 2022
indygreg created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.
REVISION SUMMARY
We no longer support Python 2 so we can drop support for linting code
for Python 2 support.
This gets rid of the check for `from __future__`, enabling us to delete
those imports.
REPOSITORY
rHG Mercurial
BRANCH
default
REVISION DETAIL
https://phab.mercurial-scm.org/D12251
AFFECTED FILES
contrib/check-py3-compat.py
CHANGE DETAILS
diff --git a/contrib/check-py3-compat.py b/contrib/check-py3-compat.py
--- a/contrib/check-py3-compat.py
+++ b/contrib/check-py3-compat.py
@@ -17,31 +17,6 @@
import warnings
-def check_compat_py2(f):
- """Check Python 3 compatibility for a file with Python 2"""
- with open(f, 'rb') as fh:
- content = fh.read()
- root = ast.parse(content)
-
- # Ignore empty files.
- if not root.body:
- return
-
- futures = set()
- haveprint = False
- for node in ast.walk(root):
- if isinstance(node, ast.ImportFrom):
- if node.module == '__future__':
- futures |= {n.name for n in node.names}
- elif isinstance(node, ast.Print):
- haveprint = True
-
- if 'absolute_import' not in futures:
- print('%s not using absolute_import' % f)
- if haveprint and 'print_function' not in futures:
- print('%s requires print_function' % f)
-
-
def check_compat_py3(f):
"""Check Python 3 compatibility of a file with Python 3."""
with open(f, 'rb') as fh:
@@ -94,23 +69,19 @@
if __name__ == '__main__':
- if sys.version_info[0] == 2:
- fn = check_compat_py2
- else:
- # check_compat_py3 will import every filename we specify as long as it
- # starts with one of a few prefixes. It does this by converting
- # specified filenames like 'mercurial/foo.py' to 'mercurial.foo' and
- # importing that. When running standalone (not as part of a test), this
- # means we actually import the installed versions, not the files we just
- # specified. When running as test-check-py3-compat.t, we technically
- # would import the correct paths, but it's cleaner to have both cases
- # use the same import logic.
- sys.path.insert(0, '.')
- fn = check_compat_py3
+ # check_compat_py3 will import every filename we specify as long as it
+ # starts with one of a few prefixes. It does this by converting
+ # specified filenames like 'mercurial/foo.py' to 'mercurial.foo' and
+ # importing that. When running standalone (not as part of a test), this
+ # means we actually import the installed versions, not the files we just
+ # specified. When running as test-check-py3-compat.t, we technically
+ # would import the correct paths, but it's cleaner to have both cases
+ # use the same import logic.
+ sys.path.insert(0, '.')
for f in sys.argv[1:]:
with warnings.catch_warnings(record=True) as warns:
- fn(f)
+ check_compat_py3(f)
for w in warns:
print(
To: indygreg, #hg-reviewers
Cc: mercurial-patches, mercurial-devel
More information about the Mercurial-devel
mailing list