Fix deprecation warnings under py36
This addresses two sources of deprecation warnings. The collections package has moved ABC classes under collections.abc. Six does not support this move yet, so this updates the code to try to import from the newer locations, and if that fails, import from the old location. Py36 is also more strict about escape sequences in strings. This happens move often with regex strings that are valid regex but not a valid normal string escape sequence. This addresses those errors by switching to raw strings. Change-Id: I4c61df6b6432b135297f38c02b4538e4ba56be51 Signed-off-by: Sean McGinnis <sean.mcginnis@gmail.com>
This commit is contained in:
parent
57333e902a
commit
3c50cb5cce
1
.gitignore
vendored
1
.gitignore
vendored
@ -23,6 +23,7 @@ AUTHORS
|
||||
.update-venv/
|
||||
ChangeLog
|
||||
*.egg
|
||||
*.eggs
|
||||
.stestr/
|
||||
oslo.db.egg-info/
|
||||
doc/source/reference/api
|
||||
|
@ -195,15 +195,16 @@ def _sqlite_dupe_key_error(integrity_error, match, engine_name, is_disconnect):
|
||||
r"(?i).*foreign key constraint failed")
|
||||
@filters("postgresql", sqla_exc.IntegrityError,
|
||||
r".*on table \"(?P<table>[^\"]+)\" violates "
|
||||
"foreign key constraint \"(?P<constraint>[^\"]+)\".*\n"
|
||||
"DETAIL: Key \((?P<key>.+)\)=\(.+\) "
|
||||
"is (not present in|still referenced from) table "
|
||||
"\"(?P<key_table>[^\"]+)\".")
|
||||
@filters("mysql", sqla_exc.IntegrityError,
|
||||
r".*Cannot (add|delete) or update a (child|parent) row: "
|
||||
'a foreign key constraint fails \([`"].+[`"]\.[`"](?P<table>.+)[`"], '
|
||||
'CONSTRAINT [`"](?P<constraint>.+)[`"] FOREIGN KEY '
|
||||
'\([`"](?P<key>.+)[`"]\) REFERENCES [`"](?P<key_table>.+)[`"] ')
|
||||
r"foreign key constraint \"(?P<constraint>[^\"]+)\".*\n"
|
||||
r"DETAIL: Key \((?P<key>.+)\)=\(.+\) "
|
||||
r"is (not present in|still referenced from) table "
|
||||
r"\"(?P<key_table>[^\"]+)\".")
|
||||
@filters(
|
||||
"mysql", sqla_exc.IntegrityError,
|
||||
r".*Cannot (add|delete) or update a (child|parent) row: "
|
||||
r'a foreign key constraint fails \([`"].+[`"]\.[`"](?P<table>.+)[`"], '
|
||||
r'CONSTRAINT [`"](?P<constraint>.+)[`"] FOREIGN KEY '
|
||||
r'\([`"](?P<key>.+)[`"]\) REFERENCES [`"](?P<key_table>.+)[`"] ')
|
||||
def _foreign_key_error(integrity_error, match, engine_name, is_disconnect):
|
||||
"""Filter for foreign key errors."""
|
||||
|
||||
|
@ -17,6 +17,12 @@
|
||||
# under the License.
|
||||
|
||||
import collections
|
||||
# TODO(smcginnis) update this once six has support for collections.abc
|
||||
# (https://github.com/benjaminp/six/pull/241) or clean up once we drop py2.7.
|
||||
try:
|
||||
from collections.abc import Iterable
|
||||
except ImportError:
|
||||
from collections import Iterable
|
||||
import contextlib
|
||||
import inspect as pyinspect
|
||||
import itertools
|
||||
@ -280,8 +286,7 @@ def paginate_query(query, model, limit, sort_keys, marker=None,
|
||||
def to_list(x, default=None):
|
||||
if x is None:
|
||||
return default
|
||||
if not isinstance(x, collections.Iterable) or \
|
||||
isinstance(x, six.string_types):
|
||||
if not isinstance(x, Iterable) or isinstance(x, six.string_types):
|
||||
return [x]
|
||||
elif isinstance(x, list):
|
||||
return x
|
||||
|
@ -13,7 +13,12 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import collections
|
||||
# TODO(smcginnis) update this once six has support for collections.abc
|
||||
# (https://github.com/benjaminp/six/pull/241) or clean up once we drop py2.7.
|
||||
try:
|
||||
from collections.abc import Iterable
|
||||
except ImportError:
|
||||
from collections import Iterable
|
||||
import datetime
|
||||
|
||||
import mock
|
||||
@ -51,7 +56,7 @@ class ModelBaseTest(test_base._DbTestCase):
|
||||
"Method %s() is not found" % method)
|
||||
|
||||
def test_modelbase_is_iterable(self):
|
||||
self.assertTrue(issubclass(models.ModelBase, collections.Iterable))
|
||||
self.assertTrue(issubclass(models.ModelBase, Iterable))
|
||||
|
||||
def test_modelbase_set(self):
|
||||
self.mb['world'] = 'hello'
|
||||
|
Loading…
Reference in New Issue
Block a user