From d9d3f1029681ee46299e0e150430674e0f702f52 Mon Sep 17 00:00:00 2001 From: Matthias Bussonnier Date: Wed, 7 Feb 2024 11:46:07 +0100 Subject: [PATCH 1/2] More removal of Six dependency. We are Python 3 only now, we can simplify all those codepath. --- lib/python/pyflyby/_autoimp.py | 2 +- lib/python/pyflyby/_format.py | 5 +---- lib/python/pyflyby/_importclns.py | 27 +++++++++++++-------------- lib/python/pyflyby/_livepatch.py | 4 ++-- lib/python/pyflyby/_util.py | 6 +++--- 5 files changed, 20 insertions(+), 24 deletions(-) diff --git a/lib/python/pyflyby/_autoimp.py b/lib/python/pyflyby/_autoimp.py index a8dd0fef..d3468357 100644 --- a/lib/python/pyflyby/_autoimp.py +++ b/lib/python/pyflyby/_autoimp.py @@ -1002,7 +1002,7 @@ def _scan_unused_imports(self): if unused_imports is None: return scope = self.scopestack[-1] - for name, value in six.iteritems(scope): + for name, value in scope.items(): if not isinstance(value, _UseChecker): continue if value.used: diff --git a/lib/python/pyflyby/_format.py b/lib/python/pyflyby/_format.py index cff341ba..2ff6809f 100644 --- a/lib/python/pyflyby/_format.py +++ b/lib/python/pyflyby/_format.py @@ -4,9 +4,6 @@ -import six - - class FormatParams(object): max_line_length = None _max_line_lenght_default = 79 @@ -33,7 +30,7 @@ def __new__(cls, *args, **kwargs): if kwargs: dicts.append(kwargs) for kwargs in dicts: - for key, value in six.iteritems(kwargs): + for key, value in kwargs.items(): if hasattr(self, key): setattr(self, key, value) else: diff --git a/lib/python/pyflyby/_importclns.py b/lib/python/pyflyby/_importclns.py index 395a86b8..622221fd 100644 --- a/lib/python/pyflyby/_importclns.py +++ b/lib/python/pyflyby/_importclns.py @@ -17,6 +17,8 @@ from pyflyby._util import (cached_attribute, cmp, partition, stable_unique) +from typing import Dict + class NoSuchImportError(ValueError): pass @@ -228,9 +230,9 @@ def _by_module_name(self): else: frm_imports[module_name].add(imp) return tuple( - dict( (k, frozenset(v)) - for k, v in six.iteritems(imports)) - for imports in [ftr_imports, pkg_imports, frm_imports]) + dict((k, frozenset(v)) for k, v in imports.items()) + for imports in [ftr_imports, pkg_imports, frm_imports] + ) def get_statements(self, separate_from_imports=True): """ @@ -261,8 +263,8 @@ def get_statements(self, separate_from_imports=True): if not separate_from_imports: def union_dicts(*dicts): result = {} - for label, dict in enumerate(dicts): - for k, v in six.iteritems(dict): + for label, dct in enumerate(dicts): + for k, v in dct.items(): result[(k, label)] = v return result groups = [groups[0], union_dicts(*groups[1:])] @@ -317,8 +319,7 @@ def by_import_as(self): d = defaultdict(list) for imp in self._importset: d[imp.import_as].append(imp) - return dict( (k, tuple(sorted(stable_unique(v)))) - for k, v in six.iteritems(d) ) + return dict((k, tuple(sorted(stable_unique(v)))) for k, v in d.items()) @cached_attribute def member_names(self): @@ -347,8 +348,7 @@ def member_names(self): for prefix in prefixes[1:]: splt = prefix.rsplit(".", 1) d[splt[0]].add(splt[1]) - return dict( (k, tuple(sorted(v))) - for k, v in six.iteritems(d) ) + return dict((k, tuple(sorted(v))) for k, v in d.items()) @cached_attribute def conflicting_imports(self): @@ -364,10 +364,7 @@ def conflicting_imports(self): :rtype: ``bool`` """ - return tuple( - k - for k, v in six.iteritems(self.by_import_as) - if len(v) > 1 and k != "*") + return tuple(k for k, v in self.by_import_as.items() if len(v) > 1 and k != "*") @cached_attribute def flags(self): @@ -522,6 +519,8 @@ class ImportMap(object): An ``ImportMap`` is an immutable data structure. """ + _data: Dict + def __new__(cls, arg): if isinstance(arg, cls): return arg @@ -565,7 +564,7 @@ def items(self): return self._data.items() def iteritems(self): - return six.iteritems(self._data) + return self._data.items() def iterkeys(self): return six.iterkeys(self._data) diff --git a/lib/python/pyflyby/_livepatch.py b/lib/python/pyflyby/_livepatch.py index 29fc775e..157a3902 100644 --- a/lib/python/pyflyby/_livepatch.py +++ b/lib/python/pyflyby/_livepatch.py @@ -369,7 +369,7 @@ def _livepatch__function(old_func, new_func, modname, cache, visit_stack): if type(oldcellv) != type(newcellv): return new_func if isinstance(oldcellv, ( - types.FunctionType, types.MethodType, six.class_types, dict)): + types.FunctionType, types.MethodType, type, dict)): # Updateable type. (Todo: make this configured globally.) continue try: @@ -546,7 +546,7 @@ def _get_definition_module(obj): :rtype: ``str`` """ - if isinstance(obj, (type, six.class_types, types.FunctionType, + if isinstance(obj, (type, types.FunctionType, types.MethodType)): return getattr(obj, "__module__", None) else: diff --git a/lib/python/pyflyby/_util.py b/lib/python/pyflyby/_util.py index 13487189..31b9e13b 100644 --- a/lib/python/pyflyby/_util.py +++ b/lib/python/pyflyby/_util.py @@ -237,11 +237,11 @@ def __call__(self, *args, **kwargs): for k in variables: old[k] = globals.get(k, UNSET) try: - for k, v in six.iteritems(variables): + for k, v in variables.items(): globals[k] = v return function(*args, **kwargs) finally: - for k, v in six.iteritems(old): + for k, v in old.items(): if v is UNSET: del globals[k] else: @@ -335,7 +335,7 @@ def __init__(self, joinpoint): while hasattr(joinpoint, "__joinpoint__"): joinpoint = joinpoint.__joinpoint__ self._joinpoint = joinpoint - if (isinstance(joinpoint, (types.FunctionType, six.class_types, type)) + if (isinstance(joinpoint, (types.FunctionType, type)) and not (joinpoint.__name__ != joinpoint.__qualname__)): self._qname = "%s.%s" % ( joinpoint.__module__, From a2aea0735d2130b6fa3e3b112c177e2102facc21 Mon Sep 17 00:00:00 2001 From: Matthias Bussonnier Date: Wed, 7 Feb 2024 12:14:11 +0100 Subject: [PATCH 2/2] remove imports --- lib/python/pyflyby/_livepatch.py | 1 - lib/python/pyflyby/_util.py | 1 - 2 files changed, 2 deletions(-) diff --git a/lib/python/pyflyby/_livepatch.py b/lib/python/pyflyby/_livepatch.py index 157a3902..efbaa0d2 100644 --- a/lib/python/pyflyby/_livepatch.py +++ b/lib/python/pyflyby/_livepatch.py @@ -134,7 +134,6 @@ def __livepatch__(self, old, do_livepatch): import ast import os import re -import six import sys import time import types diff --git a/lib/python/pyflyby/_util.py b/lib/python/pyflyby/_util.py index 31b9e13b..aeab5af6 100644 --- a/lib/python/pyflyby/_util.py +++ b/lib/python/pyflyby/_util.py @@ -7,7 +7,6 @@ from contextlib import contextmanager import inspect import os -import six from six import reraise import sys import types