Commit 64a42d07 authored by Jérome Perrin's avatar Jérome Perrin

ZMySQLDA: use contextlib.nullcontext instead of nested

nested warns where it is used and the modern approach for this is
contextlib.nullcontext
parent e921bbca
...@@ -94,9 +94,11 @@ from MySQLdb import OperationalError, NotSupportedError, ProgrammingError, _mysq ...@@ -94,9 +94,11 @@ from MySQLdb import OperationalError, NotSupportedError, ProgrammingError, _mysq
import warnings import warnings
from contextlib import contextmanager from contextlib import contextmanager
if six.PY2: if six.PY2:
from contextlib import nested @contextmanager
def nullcontext():
yield
else: else:
from contextlib import ExitStack as nested from contextlib import nullcontext
from Products.ERP5Type.Timeout import TimeoutReachedError, getTimeLeft from Products.ERP5Type.Timeout import TimeoutReachedError, getTimeLeft
MySQLdb_version_required = (0,9,2) MySQLdb_version_required = (0,9,2)
...@@ -582,7 +584,7 @@ class DB(TM): ...@@ -582,7 +584,7 @@ class DB(TM):
name = m.group(2) name = m.group(2)
# Lock automatically unless src__ is True, because the caller may have # Lock automatically unless src__ is True, because the caller may have
# already done it (in case that it plans to execute the returned query). # already done it (in case that it plans to execute the returned query).
with (nested if src__ else self.lock)(): with (nullcontext if src__ else self.lock)():
try: try:
old_list, old_set, old_default = self._getTableSchema("`%s`" % name) old_list, old_set, old_default = self._getTableSchema("`%s`" % name)
except ProgrammingError as e: except ProgrammingError as e:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment