Skip to content

Commit

Permalink
Drop six and old Python versions
Browse files Browse the repository at this point in the history
  • Loading branch information
alexmojaki committed Oct 6, 2024
1 parent e1907e6 commit 5f9c50f
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 69 deletions.
1 change: 0 additions & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 6 additions & 8 deletions snoop/configuration.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand All @@ -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):
Expand Down
22 changes: 7 additions & 15 deletions snoop/formatting.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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:]
Expand Down
4 changes: 1 addition & 3 deletions snoop/pp_module.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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)


Expand Down Expand Up @@ -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)
Expand Down
13 changes: 5 additions & 8 deletions snoop/tracer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand Down Expand Up @@ -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=(),
Expand Down Expand Up @@ -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)
Expand Down
21 changes: 2 additions & 19 deletions snoop/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__'

Expand Down Expand Up @@ -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,)
Expand Down Expand Up @@ -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
Expand Down
8 changes: 1 addition & 7 deletions snoop/variables.py
Original file line number Diff line number Diff line change
@@ -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=()):
Expand Down
11 changes: 3 additions & 8 deletions tests/test_snoop.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)

0 comments on commit 5f9c50f

Please sign in to comment.