mirror of
https://github.com/jlu5/PyLink.git
synced 2024-11-01 01:09:22 +01:00
utils, Irc: add abstraction to warn on deprecated attribute usage (#273)
This commit is contained in:
parent
47f0b7626f
commit
7f070448b7
@ -33,7 +33,7 @@ class ProtocolError(Exception):
|
||||
|
||||
### Internal classes (users, servers, channels)
|
||||
|
||||
class Irc():
|
||||
class Irc(utils.DeprecatedAttributesObject):
|
||||
"""Base IRC object for PyLink."""
|
||||
|
||||
def __init__(self, netname, proto, conf):
|
||||
@ -42,6 +42,8 @@ class Irc():
|
||||
(a string), the name of the protocol module to use for this connection,
|
||||
and a configuration object.
|
||||
"""
|
||||
self.deprecated_attributes = {'conf': 'Deprecated since 1.2; consider switching to conf.conf'}
|
||||
|
||||
self.loghandlers = []
|
||||
self.name = netname
|
||||
self.conf = conf
|
||||
|
14
utils.py
14
utils.py
@ -560,3 +560,17 @@ class IRCParser(argparse.ArgumentParser):
|
||||
|
||||
def error(self, message):
|
||||
raise InvalidArgumentsError(message)
|
||||
|
||||
class DeprecatedAttributesObject():
|
||||
"""
|
||||
Object implementing deprecated attributes and warnings on access.
|
||||
"""
|
||||
|
||||
def __getattribute__(self, attr):
|
||||
# Note: "self.deprecated_attributes" calls this too, so the != check is
|
||||
# needed to prevent a recursive loop!
|
||||
if attr != 'deprecated_attributes' and attr in self.deprecated_attributes:
|
||||
log.warning('Attribute %s.%s is deprecated: %s' % (self.__class__.__name__, attr,
|
||||
self.deprecated_attributes.get(attr)))
|
||||
|
||||
return object.__getattribute__(self, attr)
|
||||
|
Loading…
Reference in New Issue
Block a user