diff --git a/setup.cfg b/setup.cfg index 14302cc..9c2b19e 100644 --- a/setup.cfg +++ b/setup.cfg @@ -29,7 +29,6 @@ include_package_data = True setup_requires = setuptools; setuptools_scm[toml] python_requires = >=3.8 install_requires = - six cheap_repr>=0.4.0 executing asttokens diff --git a/snoop/configuration.py b/snoop/configuration.py index 96b418a..1c8faf9 100644 --- a/snoop/configuration.py +++ b/snoop/configuration.py @@ -1,17 +1,15 @@ import inspect import os -import pprint import sys import threading +from collections.abc import Mapping, Sequence, Set from io import open -import six - import snoop as package from snoop.formatting import DefaultFormatter from snoop.pp_module import PP from snoop.tracer import Spy, Tracer -from snoop.utils import Mapping, QuerySet, Sequence, Set +from snoop.utils import QuerySet from snoop.utils import builtins as builtins_module from snoop.utils import ensure_tuple, is_pathlike, shitcode @@ -166,7 +164,7 @@ def len_shape_watch(source, value): length = len(value) if ( - (isinstance(value, six.string_types) + (isinstance(value, (str, bytes)) and length < 50) or (isinstance(value, (Mapping, Set, Sequence)) and length == 0) @@ -184,8 +182,8 @@ def dtype_watch(source, value): def get_write_function(output, overwrite): is_path = ( - isinstance(output, six.string_types) - or is_pathlike(output) + isinstance(output, str) + or is_pathlike(output) ) if is_path: return FileWriter(output, overwrite).write @@ -211,7 +209,7 @@ def write(s): class FileWriter(object): def __init__(self, path, overwrite): - self.path = six.text_type(path) + self.path = str(path) self.overwrite = overwrite def write(self, s): diff --git a/snoop/formatting.py b/snoop/formatting.py index bd52c58..2870255 100644 --- a/snoop/formatting.py +++ b/snoop/formatting.py @@ -7,22 +7,15 @@ import executing import opcode -import six from pygments import highlight from pygments.formatters.terminal256 import Terminal256Formatter from pygments.lexers.python import Python3Lexer from pygments.styles.monokai import MonokaiStyle -from six import PY3 - -from snoop.utils import (NO_ASTTOKENS, ArgDefaultDict, FormattedValue, - ensure_tuple, lru_cache, my_cheap_repr, +from functools import lru_cache +from snoop.utils import (ArgDefaultDict, FormattedValue, + ensure_tuple, my_cheap_repr, optional_numeric_label, short_filename, try_statement) -try: - from pygments.lexers.python import Python2Lexer -except ImportError: - from pygments.lexers.python import PythonLexer as Python2Lexer - class StatementsDict(dict): def __init__(self, source): @@ -85,7 +78,7 @@ def get_text_with_indentation(self, node): return result -lexer = (Python3Lexer if PY3 else Python2Lexer)(stripnl=False) +lexer = Python3Lexer(stripnl=False) class ForceWhiteTerminal256Formatter(Terminal256Formatter): @@ -177,7 +170,7 @@ class DefaultFormatter(object): datetime_format = None def __init__(self, prefix, columns, color): - prefix = six.text_type(prefix) + prefix = str(prefix) if prefix and prefix == prefix.rstrip(): prefix += u' ' self.prefix = prefix @@ -385,7 +378,6 @@ def format_start(self, event): def format_executing_node_exception(self, event): try: - assert not NO_ASTTOKENS ex = Source.executing(event.frame) decorator = getattr(ex, "decorator", None) node = decorator or ex.node @@ -414,7 +406,7 @@ def format_executing_node_exception(self, event): def columns_string(self, event): column_strings = [] for column in self.columns: - string = six.text_type(column(event)) + string = str(column(event)) width = self.column_widths[column] = max( self.column_widths[column], len(string), @@ -499,7 +491,7 @@ class Colors(object): def indented_lines(prefix, string, plain_prefix=None): - lines = six.text_type(string).splitlines() or [''] + lines = str(string).splitlines() or [''] return [prefix + lines[0]] + [ u' ' * len(plain_prefix or prefix) + line for line in lines[1:] diff --git a/snoop/pp_module.py b/snoop/pp_module.py index 9375b63..0478a4d 100644 --- a/snoop/pp_module.py +++ b/snoop/pp_module.py @@ -1,7 +1,6 @@ import ast import inspect import traceback -import warnings from copy import deepcopy from threading import current_thread from uuid import uuid4 @@ -10,7 +9,7 @@ from snoop.formatting import Event, Source from snoop.tracer import FrameInfo -from snoop.utils import (NO_ASTTOKENS, FormattedValue, builtins, +from snoop.utils import (FormattedValue, builtins, optional_numeric_label, pp_name_prefix) @@ -49,7 +48,6 @@ def __init__(self, pp_object, args, deep): self.returns = None try: - assert not NO_ASTTOKENS self.call = call = Source.executing(frame).node assert isinstance(call, ast.Call) assert len(args) == len(call.args) diff --git a/snoop/tracer.py b/snoop/tracer.py index 222f28a..f78e2ee 100644 --- a/snoop/tracer.py +++ b/snoop/tracer.py @@ -6,11 +6,10 @@ import threading from collections import OrderedDict -import six # noinspection PyUnresolvedReferences from cheap_repr import cheap_repr, find_repr_function, try_register_repr -from snoop.utils import (NO_BIRDSEYE, PY34, ArgDefaultDict, +from snoop.utils import (NO_BIRDSEYE, ArgDefaultDict, _register_cheap_reprs, ensure_tuple, is_comprehension_frame, iscoroutinefunction, my_cheap_repr, no_args_decorator, pp_name_prefix, @@ -19,8 +18,8 @@ from .formatting import Event, Source from .variables import BaseVariable, CommonVariable, Exploding -find_repr_function(six.text_type).maxparts = 100 -find_repr_function(six.binary_type).maxparts = 100 +find_repr_function(str).maxparts = 100 +find_repr_function(bytes).maxparts = 100 find_repr_function(object).maxparts = 100 find_repr_function(int).maxparts = 999999 cheap_repr.suppression_threshold = 999999 @@ -139,8 +138,7 @@ def __exit__(self, *args): return self.default.__exit__(*args, context=1) -@six.add_metaclass(TracerMeta) -class Tracer(object): +class Tracer(metaclass=TracerMeta): def __init__( self, watch=(), @@ -216,8 +214,7 @@ def __exit__(self, exc_type, exc_value, exc_traceback, context=0): previous_trace = thread_global.original_trace_functions.pop() sys.settrace(previous_trace) calling_frame = sys._getframe(context + 1) - if not (PY34 and previous_trace is None): - calling_frame.f_trace = previous_trace + calling_frame.f_trace = previous_trace self.trace(calling_frame, 'exit', None) self.target_frames.discard(calling_frame) self.frame_infos.pop(calling_frame, None) diff --git a/snoop/utils.py b/snoop/utils.py index 478ab55..9ca0691 100644 --- a/snoop/utils.py +++ b/snoop/utils.py @@ -4,13 +4,10 @@ import sys from itertools import chain -import six from cheap_repr import cheap_repr, try_register_repr -PY34 = sys.version_info[:2] == (3, 4) -NO_ASTTOKENS = PY34 PYPY = 'pypy' in sys.version.lower() -NO_BIRDSEYE = NO_ASTTOKENS or PYPY +NO_BIRDSEYE = PYPY pp_name_prefix = '__deep_pp_hidden__' @@ -44,7 +41,7 @@ def truncate_list(lst, max_length): def ensure_tuple(x, split=False): - if split and isinstance(x, six.string_types): + if split and isinstance(x, str): x = x.replace(',', ' ').split() if not isinstance(x, (list, set, tuple)): x = (x,) @@ -148,20 +145,6 @@ def no_args_decorator(args, kwargs): return len(args) == 1 and inspect.isfunction(args[0]) and not kwargs -try: - from functools import lru_cache -except ImportError: - from backports.functools_lru_cache import lru_cache - - -if six.PY2: - # noinspection PyUnresolvedReferences - from collections import Mapping, Sequence, Set -else: - # noinspection PyUnresolvedReferences,PyCompatibility - from collections.abc import Mapping, Sequence, Set - - class DirectRepr(str): def __repr__(self): return self diff --git a/snoop/variables.py b/snoop/variables.py index 2b0c4d0..aaf8a78 100644 --- a/snoop/variables.py +++ b/snoop/variables.py @@ -1,15 +1,9 @@ import itertools +from collections.abc import Mapping, Sequence from copy import deepcopy -import six - from snoop.utils import ensure_tuple, my_cheap_repr, with_needed_parentheses -if six.PY2: - from collections import Mapping, Sequence -else: - from collections.abc import Mapping, Sequence - class BaseVariable(object): def __init__(self, source, exclude=()): diff --git a/tests/test_snoop.py b/tests/test_snoop.py index 63d3e91..722fddf 100644 --- a/tests/test_snoop.py +++ b/tests/test_snoop.py @@ -10,7 +10,6 @@ from threading import current_thread import pytest -import six from cheap_repr import cheap_repr, register_repr from cheap_repr.utils import safe_qualname from littleutils import file_to_string, group_by_key_func, string_to_file @@ -22,7 +21,7 @@ from snoop import formatting, install, spy from snoop.configuration import Config from snoop.pp_module import is_deep_arg -from snoop.utils import (NO_ASTTOKENS, NO_BIRDSEYE, PYPY, needs_parentheses, +from snoop.utils import (NO_BIRDSEYE, PYPY, needs_parentheses, truncate_list, truncate_string) formatting._get_filename = lambda _: "/path/to_file.py" @@ -58,7 +57,6 @@ def sample_traceback(): tb = u''.join( line for line in raw if not line.strip().startswith("File") - if not line.strip() == "raise value" # part of six.reraise ) sys.stderr.write(tb) @@ -112,14 +110,11 @@ def generate_test_samples(): for filename in os.listdir(samples_dir): if filename.endswith('.pyc'): continue - module_name = six.text_type(filename.split('.')[0]) + module_name = str(filename.split('.')[0]) if module_name in '__init__ __pycache__': continue - if module_name in 'django_sample'.split() and six.PY2: - continue - if PYPY or sys.version_info[:2] in ((3, 4), (3, 10)): if module_name in 'pandas_sample'.split(): continue @@ -305,6 +300,6 @@ def test_is_deep_arg(): def test_no_asttokens_spy(): - if NO_ASTTOKENS: + if PYPY: with pytest.raises(Exception, match="birdseye doesn't support this version of Python"): spy(test_is_deep_arg)