From 3d03d8816ae02125d1ad036c72cb6bd512a20930 Mon Sep 17 00:00:00 2001 From: Victor Uriarte Date: Thu, 2 Jun 2016 12:40:22 -0700 Subject: Update TokenType magic methods (contains, getattr, repr) Variables were renamed to keep with convention getattr call to tuple (super) is unnecessary. --- sqlparse/tokens.py | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) (limited to 'sqlparse') 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() -- cgit v1.2.1