Skip to content

Commit e5ba978

Browse files
author
brett.cannon
committed
Remove dict.has_key() and apply() usage from the logging package to silence
warnings when run under -3. git-svn-id: http://svn.python.org/projects/python/trunk@65457 6015fed2-1504-0410-9fe1-9d1591cc4771
1 parent 37b8209 commit e5ba978

2 files changed

Lines changed: 17 additions & 17 deletions

File tree

Lib/logging/__init__.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -898,7 +898,7 @@ def getLogger(self, name):
898898
rv = None
899899
_acquireLock()
900900
try:
901-
if self.loggerDict.has_key(name):
901+
if name in self.loggerDict:
902902
rv = self.loggerDict[name]
903903
if isinstance(rv, PlaceHolder):
904904
ph = rv
@@ -926,7 +926,7 @@ def _fixupParents(self, alogger):
926926
rv = None
927927
while (i > 0) and not rv:
928928
substr = name[:i]
929-
if not self.loggerDict.has_key(substr):
929+
if substr not in self.loggerDict:
930930
self.loggerDict[substr] = PlaceHolder(alogger)
931931
else:
932932
obj = self.loggerDict[substr]
@@ -1001,7 +1001,7 @@ def debug(self, msg, *args, **kwargs):
10011001
logger.debug("Houston, we have a %s", "thorny problem", exc_info=1)
10021002
"""
10031003
if self.isEnabledFor(DEBUG):
1004-
apply(self._log, (DEBUG, msg, args), kwargs)
1004+
self._log(DEBUG, msg, args, **kwargs)
10051005

10061006
def info(self, msg, *args, **kwargs):
10071007
"""
@@ -1013,7 +1013,7 @@ def info(self, msg, *args, **kwargs):
10131013
logger.info("Houston, we have a %s", "interesting problem", exc_info=1)
10141014
"""
10151015
if self.isEnabledFor(INFO):
1016-
apply(self._log, (INFO, msg, args), kwargs)
1016+
self._log(INFO, msg, args, **kwargs)
10171017

10181018
def warning(self, msg, *args, **kwargs):
10191019
"""
@@ -1025,7 +1025,7 @@ def warning(self, msg, *args, **kwargs):
10251025
logger.warning("Houston, we have a %s", "bit of a problem", exc_info=1)
10261026
"""
10271027
if self.isEnabledFor(WARNING):
1028-
apply(self._log, (WARNING, msg, args), kwargs)
1028+
self._log(WARNING, msg, args, **kwargs)
10291029

10301030
warn = warning
10311031

@@ -1039,13 +1039,13 @@ def error(self, msg, *args, **kwargs):
10391039
logger.error("Houston, we have a %s", "major problem", exc_info=1)
10401040
"""
10411041
if self.isEnabledFor(ERROR):
1042-
apply(self._log, (ERROR, msg, args), kwargs)
1042+
self._log(ERROR, msg, args, **kwargs)
10431043

10441044
def exception(self, msg, *args):
10451045
"""
10461046
Convenience method for logging an ERROR with exception information.
10471047
"""
1048-
apply(self.error, (msg,) + args, {'exc_info': 1})
1048+
self.error(*((msg,) + args), **{'exc_info': 1})
10491049

10501050
def critical(self, msg, *args, **kwargs):
10511051
"""
@@ -1057,7 +1057,7 @@ def critical(self, msg, *args, **kwargs):
10571057
logger.critical("Houston, we have a %s", "major disaster", exc_info=1)
10581058
"""
10591059
if self.isEnabledFor(CRITICAL):
1060-
apply(self._log, (CRITICAL, msg, args), kwargs)
1060+
self._log(CRITICAL, msg, args, **kwargs)
10611061

10621062
fatal = critical
10631063

@@ -1076,7 +1076,7 @@ def log(self, level, msg, *args, **kwargs):
10761076
else:
10771077
return
10781078
if self.isEnabledFor(level):
1079-
apply(self._log, (level, msg, args), kwargs)
1079+
self._log(level, msg, args, **kwargs)
10801080

10811081
def findCaller(self):
10821082
"""
@@ -1394,7 +1394,7 @@ def critical(msg, *args, **kwargs):
13941394
"""
13951395
if len(root.handlers) == 0:
13961396
basicConfig()
1397-
apply(root.critical, (msg,)+args, kwargs)
1397+
root.critical(*((msg,)+args), **kwargs)
13981398

13991399
fatal = critical
14001400

@@ -1404,22 +1404,22 @@ def error(msg, *args, **kwargs):
14041404
"""
14051405
if len(root.handlers) == 0:
14061406
basicConfig()
1407-
apply(root.error, (msg,)+args, kwargs)
1407+
root.error(*((msg,)+args), **kwargs)
14081408

14091409
def exception(msg, *args):
14101410
"""
14111411
Log a message with severity 'ERROR' on the root logger,
14121412
with exception information.
14131413
"""
1414-
apply(error, (msg,)+args, {'exc_info': 1})
1414+
error(*((msg,)+args), **{'exc_info': 1})
14151415

14161416
def warning(msg, *args, **kwargs):
14171417
"""
14181418
Log a message with severity 'WARNING' on the root logger.
14191419
"""
14201420
if len(root.handlers) == 0:
14211421
basicConfig()
1422-
apply(root.warning, (msg,)+args, kwargs)
1422+
root.warning(*((msg,)+args), **kwargs)
14231423

14241424
warn = warning
14251425

@@ -1429,23 +1429,23 @@ def info(msg, *args, **kwargs):
14291429
"""
14301430
if len(root.handlers) == 0:
14311431
basicConfig()
1432-
apply(root.info, (msg,)+args, kwargs)
1432+
root.info(*((msg,)+args), **kwargs)
14331433

14341434
def debug(msg, *args, **kwargs):
14351435
"""
14361436
Log a message with severity 'DEBUG' on the root logger.
14371437
"""
14381438
if len(root.handlers) == 0:
14391439
basicConfig()
1440-
apply(root.debug, (msg,)+args, kwargs)
1440+
root.debug(*((msg,)+args), **kwargs)
14411441

14421442
def log(level, msg, *args, **kwargs):
14431443
"""
14441444
Log 'msg % args' with the integer severity 'level' on the root logger.
14451445
"""
14461446
if len(root.handlers) == 0:
14471447
basicConfig()
1448-
apply(root.log, (level, msg)+args, kwargs)
1448+
root.log(*((level, msg)+args), **kwargs)
14491449

14501450
def disable(level):
14511451
"""

Lib/logging/config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ def _install_handlers(cp, formatters):
152152
klass = _resolve(klass)
153153
args = cp.get(sectname, "args")
154154
args = eval(args, vars(logging))
155-
h = apply(klass, args)
155+
h = klass(*args)
156156
if "level" in opts:
157157
level = cp.get(sectname, "level")
158158
h.setLevel(logging._levelNames[level])

0 commit comments

Comments
 (0)