Skip to content

Commit

Permalink
Merge pull request #297 from Carreau/less-six
Browse files Browse the repository at this point in the history
More removal of Six dependency.
  • Loading branch information
Carreau authored Feb 7, 2024
2 parents 8a6e6ca + a2aea07 commit 547d4ef
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 26 deletions.
2 changes: 1 addition & 1 deletion lib/python/pyflyby/_autoimp.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
5 changes: 1 addition & 4 deletions lib/python/pyflyby/_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@



import six


class FormatParams(object):
max_line_length = None
_max_line_lenght_default = 79
Expand All @@ -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:
Expand Down
27 changes: 13 additions & 14 deletions lib/python/pyflyby/_importclns.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
from pyflyby._util import (cached_attribute, cmp, partition,
stable_unique)

from typing import Dict


class NoSuchImportError(ValueError):
pass
Expand Down Expand Up @@ -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):
"""
Expand Down Expand Up @@ -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:])]
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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):
Expand All @@ -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):
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
5 changes: 2 additions & 3 deletions lib/python/pyflyby/_livepatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,6 @@ def __livepatch__(self, old, do_livepatch):
import ast
import os
import re
import six
import sys
import time
import types
Expand Down Expand Up @@ -369,7 +368,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:
Expand Down Expand Up @@ -546,7 +545,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:
Expand Down
7 changes: 3 additions & 4 deletions lib/python/pyflyby/_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
from contextlib import contextmanager
import inspect
import os
import six
from six import reraise
import sys
import types
Expand Down Expand Up @@ -237,11 +236,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:
Expand Down Expand Up @@ -335,7 +334,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__,
Expand Down

0 comments on commit 547d4ef

Please sign in to comment.