From 4a004f87cf540bba8617d0bc359cd689c5c79b80 Mon Sep 17 00:00:00 2001 From: Matthias Bussonnier Date: Mon, 25 Mar 2024 11:43:43 +0100 Subject: [PATCH] More removal of six. This allow more types propagations. --- etc/pyflyby/std.py | 2 +- lib/python/pyflyby/_comms.py | 5 ++--- lib/python/pyflyby/_flags.py | 2 +- lib/python/pyflyby/_importclns.py | 3 +-- lib/python/pyflyby/_importdb.py | 3 +-- lib/python/pyflyby/_interactive.py | 10 ++++++---- lib/python/pyflyby/_livepatch.py | 2 +- lib/python/pyflyby/_log.py | 2 +- 8 files changed, 14 insertions(+), 15 deletions(-) diff --git a/etc/pyflyby/std.py b/etc/pyflyby/std.py index 050167e1..29252fd4 100644 --- a/etc/pyflyby/std.py +++ b/etc/pyflyby/std.py @@ -148,7 +148,7 @@ email_mime_image, email_mime_multipart, email_mime_text, http_client, map, queue, zip) -from six.moves.urllib.parse import urlencode +from urllib.parse import urlencode from six.moves.urllib.request import urlopen import smtplib from smtplib import (SMTP, SMTPAuthenticationError, diff --git a/lib/python/pyflyby/_comms.py b/lib/python/pyflyby/_comms.py index ee810e09..2d50ff34 100644 --- a/lib/python/pyflyby/_comms.py +++ b/lib/python/pyflyby/_comms.py @@ -8,7 +8,6 @@ reformat_import_statements) from pyflyby._importstmt import Import from pyflyby._log import logger -import six # These are comm targets that the frontend (lab/notebook) is expected to # open. At this point, we handle only missing imports and @@ -67,7 +66,7 @@ def initialize_comms(): def remove_comms(): - for target_name, comm in six.iteritems(comms): + for target_name, comm in comms.items(): comm.close() logger.debug("Closing comm for " + target_name) @@ -87,7 +86,7 @@ def send_comm_message(target_name, msg): def comm_close_handler(comm, message): comm_id = message["comm_id"] - for target, comm in six.iterkeys(comms): + for target, comm in comms.keys(): if comm.comm_id == comm_id: comms.pop(target) diff --git a/lib/python/pyflyby/_flags.py b/lib/python/pyflyby/_flags.py index 2a0b83cd..f0798da6 100644 --- a/lib/python/pyflyby/_flags.py +++ b/lib/python/pyflyby/_flags.py @@ -7,7 +7,7 @@ import __future__ import ast import operator -from six.moves import reduce +from functools import reduce import warnings from pyflyby._util import cached_attribute diff --git a/lib/python/pyflyby/_importclns.py b/lib/python/pyflyby/_importclns.py index d040c98f..aacadca2 100644 --- a/lib/python/pyflyby/_importclns.py +++ b/lib/python/pyflyby/_importclns.py @@ -6,7 +6,6 @@ from collections import defaultdict from functools import total_ordering -import six from pyflyby._flags import CompilerFlags from pyflyby._idents import dotted_prefixes, is_identifier @@ -567,7 +566,7 @@ def iteritems(self): return self._data.items() def iterkeys(self): - return six.iterkeys(self._data) + return iter(self._data.keys()) def keys(self): return self._data.keys() diff --git a/lib/python/pyflyby/_importdb.py b/lib/python/pyflyby/_importdb.py index 36ff6ea2..57b1628f 100644 --- a/lib/python/pyflyby/_importdb.py +++ b/lib/python/pyflyby/_importdb.py @@ -7,7 +7,6 @@ from collections import defaultdict import os import re -import six from pyflyby._file import Filename, expand_py_files_from_args, UnsafeFilenameError from pyflyby._idents import dotted_prefixes @@ -560,7 +559,7 @@ def by_fullname_or_import_as(self): for prefix in dotted_prefixes(imp.fullname)[:-1]: d[prefix].add(Import.from_parts(prefix, prefix)) return dict( (k, tuple(sorted(v - set(self.forget_imports.imports)))) - for k, v in six.iteritems(d)) + for k, v in d.items()) def __repr__(self): printed = self.pretty_print() diff --git a/lib/python/pyflyby/_interactive.py b/lib/python/pyflyby/_interactive.py index b2c4fe00..2b7691db 100644 --- a/lib/python/pyflyby/_interactive.py +++ b/lib/python/pyflyby/_interactive.py @@ -5,16 +5,16 @@ import ast +import builtins from contextlib import contextmanager import errno import inspect import os +import operator import re import subprocess import sys -import six -from six.moves import builtins from pyflyby._autoimp import (LoadSymbolError, ScopeStack, auto_eval, auto_import, @@ -37,6 +37,8 @@ __original__ = None # for pyflakes +get_method_self = operator.attrgetter('__self__') + # TODO: also support arbitrary code (in the form of a lambda and/or # assignment) as new way to do "lazy" creations, e.g. foo = a.b.c(d.e+f.g()) @@ -2098,7 +2100,7 @@ def _enable_prun_hook(self, ip): # Tested with IPython 1.0, 1.1, 1.2, 2.0, 2.1, 2.2, 2.3, 2.4, 3.0, # 3.1, 3.2, 4.0. line_magics = ip.magics_manager.magics['line'] - execmgr = six.get_method_self(line_magics['prun'])#.im_self + execmgr = get_method_self(line_magics['prun'])#.im_self if hasattr(execmgr, "_run_with_profiler"): @self._advise(execmgr._run_with_profiler) def run_with_profiler_with_autoimport(code, opts, namespace): @@ -2303,7 +2305,7 @@ def debugger_with_autoimport(*args, **kwargs): # Tested with IPython 1.0, 1.1, 1.2, 2.0, 2.1, 2.2, 2.3, 2.4, 3.0, # 3.1, 3.2, 4.0, 5.8. line_magics = ip.magics_manager.magics['line'] - execmgr = six.get_method_self(line_magics['debug']) + execmgr = get_method_self(line_magics['debug']) if hasattr(execmgr, "_run_with_debugger"): @self._advise(execmgr._run_with_debugger) def run_with_debugger_with_autoimport(code, code_ns, diff --git a/lib/python/pyflyby/_livepatch.py b/lib/python/pyflyby/_livepatch.py index efbaa0d2..3919945d 100644 --- a/lib/python/pyflyby/_livepatch.py +++ b/lib/python/pyflyby/_livepatch.py @@ -138,7 +138,7 @@ def __livepatch__(self, old, do_livepatch): import time import types -from six.moves import reload_module +from importlib import reload as reload_module import inspect from pyflyby._log import logger diff --git a/lib/python/pyflyby/_log.py b/lib/python/pyflyby/_log.py index 5c886a61..f78ac99c 100644 --- a/lib/python/pyflyby/_log.py +++ b/lib/python/pyflyby/_log.py @@ -4,11 +4,11 @@ +import builtins from contextlib import contextmanager import logging from logging import Handler, Logger import os -from six.moves import builtins import sys