diff options
author | Yilei Yang <yileiyang@google.com> | 2022-02-07 13:18:07 -0800 |
---|---|---|
committer | Copybara-Service <copybara-worker@google.com> | 2022-02-07 13:18:39 -0800 |
commit | bab9bc25509e5628fc9df80726aa89e19d505871 (patch) | |
tree | 598142c565da3f2cde037259c57efad336b2b336 /absl | |
parent | ae9d343bf198c074618add04b2b4a15df85d7728 (diff) | |
download | absl-py-bab9bc25509e5628fc9df80726aa89e19d505871.tar.gz |
Cleanup the use of `six` and future imports in `absl.logging`.
PiperOrigin-RevId: 426998346
Change-Id: I6b7ad5496864aee2bfff9b7cdff4ed70fd790a34
Diffstat (limited to 'absl')
-rw-r--r-- | absl/logging/BUILD | 1 | ||||
-rw-r--r-- | absl/logging/__init__.py | 61 | ||||
-rw-r--r-- | absl/logging/converter.py | 4 |
3 files changed, 20 insertions, 46 deletions
diff --git a/absl/logging/BUILD b/absl/logging/BUILD index d83a2b6..dbaa767 100644 --- a/absl/logging/BUILD +++ b/absl/logging/BUILD @@ -9,7 +9,6 @@ py_library( ":converter", "//absl:_collections_abc", "//absl/flags", - "@six_archive//:six", ], ) diff --git a/absl/logging/__init__.py b/absl/logging/__init__.py index c79643f..a475bd5 100644 --- a/absl/logging/__init__.py +++ b/absl/logging/__init__.py @@ -71,10 +71,6 @@ program. The differences in behavior are historical and unfortunate. """ -from __future__ import absolute_import -from __future__ import division -from __future__ import print_function - import collections import getpass import io @@ -84,6 +80,7 @@ import os import socket import struct import sys +import threading import time import timeit import traceback @@ -93,12 +90,6 @@ import warnings from absl import flags from absl._collections_abc import abc from absl.logging import converter -import six - -if six.PY2: - import thread as _thread_lib # For .get_ident(). -else: - import threading as _thread_lib # For .get_ident(). try: from typing import NoReturn @@ -257,7 +248,7 @@ class _LoggerLevelsSerializer(object): """Serializer for --logger_levels flag.""" def serialize(self, value): - if isinstance(value, six.string_types): + if isinstance(value, str): return value return ','.join( '{}:{}'.format(name, level) for name, level in value.items()) @@ -399,15 +390,11 @@ def warning(msg, *args, **kwargs): log(WARNING, msg, *args, **kwargs) -if six.PY2: - warn = warning # Deprecated function. -else: - - def warn(msg, *args, **kwargs): - """Deprecated, use 'warning' instead.""" - warnings.warn("The 'warn' function is deprecated, use 'warning' instead", - DeprecationWarning, 2) - log(WARNING, msg, *args, **kwargs) +def warn(msg, *args, **kwargs): + """Deprecated, use 'warning' instead.""" + warnings.warn("The 'warn' function is deprecated, use 'warning' instead", + DeprecationWarning, 2) + log(WARNING, msg, *args, **kwargs) def info(msg, *args, **kwargs): @@ -729,8 +716,7 @@ def find_log_dir(log_dir=None): for d in dirs: if os.path.isdir(d) and os.access(d, os.W_OK): return d - exception_class = OSError if six.PY2 else FileNotFoundError - raise exception_class( + raise FileNotFoundError( "Can't find a writable directory for logs, tried %s" % dirs) @@ -795,7 +781,7 @@ def skip_log_prefix(func): file_name = func_code.co_filename func_name = func_code.co_name func_lineno = func_code.co_firstlineno - elif isinstance(func, six.string_types): + elif isinstance(func, str): file_name = get_absl_logger().findCaller()[0] func_name = func func_lineno = None @@ -839,10 +825,7 @@ class PythonHandler(logging.StreamHandler): os.getpid()) filename = os.path.join(actual_log_dir, basename) - if six.PY2: - self.stream = open(filename, 'a') - else: - self.stream = open(filename, 'a', encoding='utf-8') + self.stream = open(filename, 'a', encoding='utf-8') # os.symlink is not available on Windows Python 2. if getattr(os, 'symlink', None): @@ -1072,16 +1055,13 @@ class ABSLLogger(logging.getLoggerClass()): (code.co_filename, code.co_name, code.co_firstlineno) not in f_to_skip and (code.co_filename, code.co_name) not in f_to_skip): - if six.PY2 and not stack_info: - return (code.co_filename, frame.f_lineno, code.co_name) - else: - sinfo = None - if stack_info: - out = io.StringIO() - out.write(u'Stack (most recent call last):\n') - traceback.print_stack(frame, file=out) - sinfo = out.getvalue().rstrip(u'\n') - return (code.co_filename, frame.f_lineno, code.co_name, sinfo) + sinfo = None + if stack_info: + out = io.StringIO() + out.write(u'Stack (most recent call last):\n') + traceback.print_stack(frame, file=out) + sinfo = out.getvalue().rstrip(u'\n') + return (code.co_filename, frame.f_lineno, code.co_name, sinfo) frame = frame.f_back def critical(self, msg, *args, **kwargs): @@ -1098,9 +1078,8 @@ class ABSLLogger(logging.getLoggerClass()): def warn(self, msg, *args, **kwargs): """Logs 'msg % args' with severity 'WARN'.""" - if six.PY3: - warnings.warn("The 'warn' method is deprecated, use 'warning' instead", - DeprecationWarning, 2) + warnings.warn("The 'warn' method is deprecated, use 'warning' instead", + DeprecationWarning, 2) self.log(logging.WARN, msg, *args, **kwargs) def warning(self, msg, *args, **kwargs): @@ -1183,7 +1162,7 @@ def _get_thread_id(): Returns: Thread ID unique to this process (unsigned) """ - thread_id = _thread_lib.get_ident() + thread_id = threading.get_ident() return thread_id & _THREAD_ID_MASK diff --git a/absl/logging/converter.py b/absl/logging/converter.py index 87f4324..53dd46d 100644 --- a/absl/logging/converter.py +++ b/absl/logging/converter.py @@ -43,10 +43,6 @@ representation, before manipulating the levels, and then only to cpp or absl if those level schemes are absolutely necessary. """ -from __future__ import absolute_import -from __future__ import division -from __future__ import print_function - import logging STANDARD_CRITICAL = logging.CRITICAL |