From 4e9c29cb58fba7e542da9b39dc0e153a9e0aca15 Mon Sep 17 00:00:00 2001 From: Alexander Bersenev Date: Tue, 14 May 2019 12:59:12 +0500 Subject: [PATCH] move the type difference declaration to pycompat --- pysnooper/pycompat.py | 10 ++++++++++ pysnooper/tracer.py | 4 ++-- pysnooper/utils.py | 13 +------------ 3 files changed, 13 insertions(+), 14 deletions(-) diff --git a/pysnooper/pycompat.py b/pysnooper/pycompat.py index b63df9d..a4cacbd 100644 --- a/pysnooper/pycompat.py +++ b/pysnooper/pycompat.py @@ -5,6 +5,7 @@ import abc import os import inspect +import sys if hasattr(abc, 'ABC'): ABC = abc.ABC @@ -42,3 +43,12 @@ try: iscoroutinefunction = inspect.iscoroutinefunction except AttributeError: iscoroutinefunction = lambda whatever: False # Lolz + +PY3 = sys.version_info[0] == 3 + +if PY3: + string_types = str, + text_type = str +else: + string_types = basestring, + text_type = unicode diff --git a/pysnooper/tracer.py b/pysnooper/tracer.py index a2b8cc4..089b817 100644 --- a/pysnooper/tracer.py +++ b/pysnooper/tracer.py @@ -92,7 +92,7 @@ def get_source_from_frame(frame): if match: encoding = match.group(1).decode('ascii') break - source = [utils.text_type(sline, encoding, 'replace') for sline in + source = [pycompat.text_type(sline, encoding, 'replace') for sline in source] source_cache[cache_key] = source @@ -126,7 +126,7 @@ def get_write_function(output, overwrite): class FileWriter(object): def __init__(self, path, overwrite): - self.path = utils.text_type(path) + self.path = pycompat.text_type(path) self.overwrite = overwrite def write(self, s): diff --git a/pysnooper/utils.py b/pysnooper/utils.py index 7376e89..199c0e9 100644 --- a/pysnooper/utils.py +++ b/pysnooper/utils.py @@ -4,18 +4,7 @@ import abc import sys -from .pycompat import ABC - -PY2 = sys.version_info[0] == 2 -PY3 = sys.version_info[0] == 3 - -if PY3: - string_types = str, - text_type = str -else: - string_types = basestring, - text_type = unicode - +from .pycompat import ABC, string_types MAX_VARIABLE_LENGTH = 100 MAX_EXCEPTION_LENGTH = 200