Merge "Make code py3-compatible (global callable())"

This commit is contained in:
Zuul 2018-08-14 21:30:16 +00:00 committed by Gerrit Code Review
commit 0cb192c2a5
5 changed files with 14 additions and 7 deletions

View File

@ -14,6 +14,7 @@
# License for the specific language governing permissions and limitations
# under the License.
import collections
import functools
import inspect
import math
@ -1088,7 +1089,7 @@ class ControllerMetaclass(type):
versioned_methods.append(getattr(base, VER_METHOD_ATTR))
for key, value in cls_dict.items():
if not callable(value):
if not isinstance(value, collections.Callable):
continue
if getattr(value, 'wsgi_action', None):
actions[value.wsgi_action] = key

View File

@ -54,7 +54,7 @@
from __future__ import print_function
import collections
import logging as python_logging
import prettytable
import sys
@ -765,7 +765,8 @@ def methods_of(obj):
"""
result = []
for i in dir(obj):
if callable(getattr(obj, i)) and not i.startswith('_'):
if isinstance(getattr(obj, i),
collections.Callable) and not i.startswith('_'):
result.append((i, getattr(obj, i)))
return result

View File

@ -14,6 +14,7 @@
"""Cinder common internal object model"""
import collections
import contextlib
import datetime
@ -160,7 +161,8 @@ class CinderObjectRegistry(base.VersionedObjectRegistry):
setattr(objects, cls.obj_name(), cls)
# If registering class has a callable initialization method, call it.
if callable(getattr(cls, 'cinder_ovo_cls_init', None)):
if isinstance(getattr(cls, 'cinder_ovo_cls_init', None),
collections.Callable):
cls.cinder_ovo_cls_init()
@ -567,7 +569,7 @@ class CinderObjectSerializer(base.VersionedObjectSerializer):
entity = self._process_iterable(context, self.serialize_entity,
entity)
elif (hasattr(entity, 'obj_to_primitive') and
callable(entity.obj_to_primitive)):
isinstance(entity.obj_to_primitive, collections.Callable)):
# NOTE(dulek): Backport outgoing object to the capped version.
backport_ver = self._get_capped_obj_version(entity)
entity = entity.obj_to_primitive(backport_ver, self.manifest)

View File

@ -13,6 +13,7 @@
# License for the specific language governing permissions and limitations
# under the License.
import collections
import inspect
import decorator
@ -224,7 +225,8 @@ class CinderCleanableObject(base.CinderPersistentObject):
# If we don't have optional decorator arguments the argument in
# decorator_args is the function we have to decorate
if len(decorator_args) == 1 and callable(decorator_args[0]):
if len(decorator_args) == 1 and isinstance(
decorator_args[0], collections.Callable):
function = decorator_args[0]
decorator_args = None
return _decorator(function)

View File

@ -15,6 +15,7 @@
Mock unit tests for the NetApp block storage driver interfaces
"""
import collections
from cinder import test
from cinder.volume.drivers.netapp.dataontap import block_cmode
@ -54,4 +55,4 @@ class NetAppBlockStorageDriverInterfaceTestCase(test.TestCase):
def _get_local_functions(self, obj):
"""Get function names of an object without superclass functions."""
return set([key for key, value in type(obj).__dict__.items()
if callable(value)])
if isinstance(value, collections.Callable)])