From 8c99b0a05f434d8826330936aa6a38df420af3f7 Mon Sep 17 00:00:00 2001 From: Matthias Bussonnier Date: Wed, 7 Feb 2024 12:26:55 +0100 Subject: [PATCH] more Six removal and cleanup of imports --- etc/pyflyby/std.py | 2 +- lib/python/pyflyby/_docxref.py | 5 ++--- lib/python/pyflyby/_flags.py | 14 +++++++++----- lib/python/pyflyby/_modules.py | 3 +-- lib/python/pyflyby/_py.py | 9 ++++----- tests/test_interactive.py | 21 +++++++++++---------- 6 files changed, 28 insertions(+), 26 deletions(-) diff --git a/etc/pyflyby/std.py b/etc/pyflyby/std.py index 5061ce97..050167e1 100644 --- a/etc/pyflyby/std.py +++ b/etc/pyflyby/std.py @@ -142,7 +142,7 @@ copytree, rmtree) import signal import six -from six import StringIO +from io import StringIO from six.moves import (builtins, cPickle, configparser, copyreg, email_mime_base, email_mime_image, email_mime_multipart, diff --git a/lib/python/pyflyby/_docxref.py b/lib/python/pyflyby/_docxref.py index c642cee5..c332f666 100644 --- a/lib/python/pyflyby/_docxref.py +++ b/lib/python/pyflyby/_docxref.py @@ -26,8 +26,7 @@ import re -import six -from six.moves import builtins +import builtins from textwrap import dedent from epydoc.apidoc import (ClassDoc, ModuleDoc, PropertyDoc, @@ -348,7 +347,7 @@ def scan_docstring(self, parsed_docstring, container): return '' def scan_tree(tree): - if isinstance(tree, six.string_types): + if isinstance(tree, str): return tree variables = [scan_tree(child) for child in tree.children] if tree.tag == 'link': diff --git a/lib/python/pyflyby/_flags.py b/lib/python/pyflyby/_flags.py index 67fa48ce..2a0b83cd 100644 --- a/lib/python/pyflyby/_flags.py +++ b/lib/python/pyflyby/_flags.py @@ -7,11 +7,11 @@ import __future__ import ast import operator -import six from six.moves import reduce import warnings from pyflyby._util import cached_attribute +from typing import Tuple # Initialize mappings from compiler_flag to feature name and vice versa. _FLAG2NAME = {} @@ -49,6 +49,10 @@ class CompilerFlags(int): """ + # technically both those are compiler flags, but we can't use Self. May need typing_extensions ? + _ZERO:int + _UNKNOWN: int + def __new__(cls, *args): """ Construct a new ``CompilerFlags`` instance. @@ -72,7 +76,7 @@ def __new__(cls, *args): ' flags values change between Python versions. If you are sure use .from_int', DeprecationWarning, stacklevel=2) return cls.from_int(arg) - elif isinstance(arg, six.string_types): + elif isinstance(arg, str): return cls.from_str(arg) elif isinstance(arg, ast.AST): return cls.from_ast(arg) @@ -100,7 +104,7 @@ def __new__(cls, *args): raise ValueError #assert flags == [0x10000, 0x8000], flags - + return cls.from_int(reduce(operator.or_, flags)) @classmethod @@ -117,7 +121,7 @@ def from_int(cls, arg): return self @classmethod - def from_str(cls, arg): + def from_str(cls, arg:str): try: flag = _NAME2FLAG[arg] except KeyError: @@ -153,7 +157,7 @@ def from_ast(cls, nodes): return cls(flags) @cached_attribute - def names(self): + def names(self) -> Tuple[str]: return tuple( n for f, n in _FLAGNAME_ITEMS diff --git a/lib/python/pyflyby/_modules.py b/lib/python/pyflyby/_modules.py index add41481..c11becaa 100644 --- a/lib/python/pyflyby/_modules.py +++ b/lib/python/pyflyby/_modules.py @@ -10,7 +10,6 @@ import itertools import os import re -import six from six import reraise import sys import types @@ -131,7 +130,7 @@ def __new__(cls, arg): return arg if isinstance(arg, Filename): return cls._from_filename(arg) - if isinstance(arg, (six.string_types, DottedIdentifier)): + if isinstance(arg, (str, DottedIdentifier)): return cls._from_modulename(arg) if isinstance(arg, types.ModuleType): return cls._from_module(arg) diff --git a/lib/python/pyflyby/_py.py b/lib/python/pyflyby/_py.py index 21060b56..ea11c21b 100644 --- a/lib/python/pyflyby/_py.py +++ b/lib/python/pyflyby/_py.py @@ -345,8 +345,7 @@ import inspect import os import re -import six -from six.moves import builtins +import builtins import sys import types from types import FunctionType, MethodType @@ -399,12 +398,12 @@ def _get_argspec(arg, _recurse=False): return _get_argspec(arg.__call__, _recurse=False) elif callable(arg): # Unknown, probably a built-in method. - return ArgSpec((), "args", "kwargs", None, [], None, {}) + return ArgSpec([], "args", "kwargs", None, [], None, {}) raise TypeError( "_get_argspec: unexpected %s" % (type(arg).__name__,)) -def _requires_parens_as_function(function_name): +def _requires_parens_as_function(function_name:str): """ Returns whether the given string of a callable would require parentheses around it to call it. @@ -638,7 +637,7 @@ def __init__(self, arg, namespace, arg_mode, source=None): if source is not None: raise ValueError( "UserExpr(): source argument not allowed for auto") - if not isinstance(arg, six.string_types): + if not isinstance(arg, str): raise ValueError( "UserExpr(): arg must be a string if arg_mode='auto'") self._original_arg_as_source = PythonBlock(arg, flags=FLAGS) diff --git a/tests/test_interactive.py b/tests/test_interactive.py index c0efec60..ce06a49f 100644 --- a/tests/test_interactive.py +++ b/tests/test_interactive.py @@ -3,27 +3,28 @@ # License for THIS FILE ONLY: CC0 Public Domain Dedication # http://creativecommons.org/publicdomain/zero/1.0/ - -import IPython import atexit -from contextlib import contextmanager import difflib -import flaky import json import os -import pexpect -import pytest import random import re import readline -import requests +import sys +import time + +from contextlib import contextmanager +from io import BytesIO from shutil import rmtree -from six import BytesIO from subprocess import check_call -import sys from tempfile import mkdtemp, mkstemp from textwrap import dedent -import time + +import IPython +import flaky +import pexpect +import pytest +import requests import pyflyby from pyflyby._file import Filename