From 293a5b5dc6019ea70e6f00621254120618eff1da Mon Sep 17 00:00:00 2001 From: Ken'ichi Ohmichi Date: Mon, 13 Mar 2017 15:13:57 -0700 Subject: [PATCH] Fix pep8 failure on py3 pep8 check failed on python3 like ./stackalytics/dashboard/vault.py:48:30: F821 undefined name 'basestring' if not isinstance(o, basestring): ./stackalytics/dashboard/vault.py:51:20: F821 undefined name 'intern' return intern(o) ./stackalytics/dashboard/vault.py:52:26: F821 undefined name 'unicode' if isinstance(o, unicode): ^ This patch fixes it by merging 2 versions of uniintern() into a single method which supports both PY2 and PY3. Change-Id: Ib18fcfffcdcc8628e7bca5b3558667fb371c956d --- stackalytics/dashboard/vault.py | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/stackalytics/dashboard/vault.py b/stackalytics/dashboard/vault.py index b960cd856..d0a42d9af 100644 --- a/stackalytics/dashboard/vault.py +++ b/stackalytics/dashboard/vault.py @@ -16,7 +16,6 @@ import collections from datetime import timedelta import os -import sys import flask from oslo_config import cfg @@ -42,23 +41,16 @@ RECORD_FIELDS_FOR_AGGREGATE = ['record_id', 'primary_key', 'record_type', CompactRecord = collections.namedtuple('CompactRecord', RECORD_FIELDS_FOR_AGGREGATE) +_unihash = {} -if six.PY2: - _unihash = {} - def uniintern(o): - if not isinstance(o, basestring): - return o - if isinstance(o, str): - return intern(o) - if isinstance(o, unicode): - return _unihash.setdefault(o, o) -else: - def uniintern(o): - if isinstance(o, str): - return sys.intern(o) - else: - return o +def uniintern(o): + if isinstance(o, str): + return six.moves.intern(o) + if not isinstance(o, six.string_types[0]): + return o + if isinstance(o, six.text_type): + return _unihash.setdefault(o, o) def compact_records(records):