summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZuul <zuul@review.openstack.org>2017-11-30 07:16:33 +0000
committerGerrit Code Review <review@openstack.org>2017-11-30 07:16:33 +0000
commit0260f0e86b1f981b21c28055eb8fcffbb803344c (patch)
treeefcaff11e2077dde47f4b5f0c382f99b19c91ae7
parent23a3293176cfecdf3ff730fc1ef2eb591c3a6ba6 (diff)
parent7a9172658848e58f33872a6224f21e24461ca783 (diff)
downloadoslo-db-4.31.0.tar.gz
Merge "Handle deprecation of inspect.getargspec"4.31.0
-rw-r--r--oslo_db/sqlalchemy/enginefacade.py4
-rw-r--r--oslo_db/sqlalchemy/utils.py20
2 files changed, 22 insertions, 2 deletions
diff --git a/oslo_db/sqlalchemy/enginefacade.py b/oslo_db/sqlalchemy/enginefacade.py
index 8213080..7871258 100644
--- a/oslo_db/sqlalchemy/enginefacade.py
+++ b/oslo_db/sqlalchemy/enginefacade.py
@@ -13,7 +13,6 @@
import contextlib
import functools
-import inspect
import operator
import threading
import warnings
@@ -27,6 +26,7 @@ from oslo_db import exception
from oslo_db import options
from oslo_db.sqlalchemy import engines
from oslo_db.sqlalchemy import orm
+from oslo_db.sqlalchemy import utils
class _symbol(object):
@@ -970,7 +970,7 @@ class _TransactionContextManager(object):
def __call__(self, fn):
"""Decorate a function."""
- argspec = inspect.getargspec(fn)
+ argspec = utils.getargspec(fn)
if argspec.args[0] == 'self' or argspec.args[0] == 'cls':
context_index = 1
else:
diff --git a/oslo_db/sqlalchemy/utils.py b/oslo_db/sqlalchemy/utils.py
index 72aa364..1a647b4 100644
--- a/oslo_db/sqlalchemy/utils.py
+++ b/oslo_db/sqlalchemy/utils.py
@@ -18,6 +18,7 @@
import collections
import contextlib
+import inspect as pyinspect
import itertools
import logging
import re
@@ -1227,6 +1228,25 @@ def suspend_fk_constraints_for_col_alter(
)
+def getargspec(fn):
+ """Inspects a function for its argspec.
+
+ This is to handle a difference between py2/3. The Python 2.x getargspec
+ call is deprecated in Python 3.x, with the suggestion to use the signature
+ call instead.
+
+ To keep compatibility with the results, while avoiding deprecation
+ warnings, this instead will use the getfullargspec instead.
+
+ :param fn: The function to inspect.
+ :returns: The argspec for the function.
+ """
+ if hasattr(pyinspect, 'getfullargspec'):
+ return pyinspect.getfullargspec(fn)
+
+ return pyinspect.getargspec(fn)
+
+
class NonCommittingConnectable(object):
"""A ``Connectable`` substitute which rolls all operations back.