summaryrefslogtreecommitdiff
path: root/sqlparse/tokens.py
diff options
context:
space:
mode:
authorVictor Uriarte <victor.m.uriarte@intel.com>2016-06-02 12:40:22 -0700
committerVictor Uriarte <victor.m.uriarte@intel.com>2016-06-02 13:16:40 -0700
commit3d03d8816ae02125d1ad036c72cb6bd512a20930 (patch)
tree39fb8c4602579ffb2441274c9656f3f59670e5fa /sqlparse/tokens.py
parent453764938f2db40593feb9ce2a85e5a2147909af (diff)
downloadsqlparse-3d03d8816ae02125d1ad036c72cb6bd512a20930.tar.gz
Update TokenType magic methods (contains, getattr, repr)
Variables were renamed to keep with convention getattr call to tuple (super) is unnecessary.
Diffstat (limited to 'sqlparse/tokens.py')
-rw-r--r--sqlparse/tokens.py15
1 files changed, 7 insertions, 8 deletions
diff --git a/sqlparse/tokens.py b/sqlparse/tokens.py
index 4d5f30e..b259627 100644
--- a/sqlparse/tokens.py
+++ b/sqlparse/tokens.py
@@ -13,19 +13,18 @@
class _TokenType(tuple):
parent = None
- def __contains__(self, val):
- return val is not None and (self is val or val[:len(self)] == self)
+ def __contains__(self, item):
+ return item is not None and (self is item or item[:len(self)] == self)
- def __getattr__(self, val):
- if not val or not val[0].isupper():
- return tuple.__getattribute__(self, val)
- new = _TokenType(self + (val,))
- setattr(self, val, new)
+ def __getattr__(self, name):
+ new = _TokenType(self + (name,))
+ setattr(self, name, new)
new.parent = self
return new
def __repr__(self):
- return 'Token' + (self and '.' or '') + '.'.join(self)
+ # self can be False only if its the `root` ie. Token itself
+ return 'Token' + ('.' if self else '') + '.'.join(self)
Token = _TokenType()