Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

more Six removal and cleanup of imports #299

Merged
merged 1 commit into from
Feb 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion etc/pyflyby/std.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
5 changes: 2 additions & 3 deletions lib/python/pyflyby/_docxref.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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':
Expand Down
14 changes: 9 additions & 5 deletions lib/python/pyflyby/_flags.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}
Expand Down Expand Up @@ -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.
Expand All @@ -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)
Expand Down Expand Up @@ -100,7 +104,7 @@ def __new__(cls, *args):
raise ValueError

#assert flags == [0x10000, 0x8000], flags

return cls.from_int(reduce(operator.or_, flags))

@classmethod
Expand All @@ -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:
Expand Down Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions lib/python/pyflyby/_modules.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import itertools
import os
import re
import six
from six import reraise
import sys
import types
Expand Down Expand Up @@ -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)
Expand Down
9 changes: 4 additions & 5 deletions lib/python/pyflyby/_py.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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)
Expand Down
21 changes: 11 additions & 10 deletions tests/test_interactive.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading