Skip to content

Commit 61bc6f4

Browse files
committed
Use new style classes and some pep8 fixes
1 parent f7a9c42 commit 61bc6f4

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

src/underscore.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from threading import Timer
99

1010

11-
class _IdCounter:
11+
class _IdCounter(object):
1212
"""
1313
A Global Dictionary for uniq IDs
1414
"""
@@ -53,7 +53,7 @@ def _(obj):
5353
return underscore(obj)
5454

5555

56-
class underscore():
56+
class underscore(object):
5757
"""
5858
Instead of creating a class named _ (underscore) I created underscore
5959
So I can use _ function both statically and dynamically just it
@@ -84,7 +84,7 @@ class underscore():
8484
Value of passed object, I assign it no Null so I can check against None results
8585
"""
8686

87-
class Namespace:
87+
class Namespace(object):
8888
"""
8989
For simulating full closure support
9090
"""
@@ -788,7 +788,7 @@ def once(self):
788788
ns.run = False
789789

790790
def work_once(*args, **kwargs):
791-
if ns.run == False:
791+
if ns.run is False:
792792
ns.memo = self.obj(*args, **kwargs)
793793
ns.run = True
794794
return ns.memo
@@ -951,7 +951,7 @@ def isEmpty(self):
951951
Is a given array, string, or object empty?
952952
An "empty" object has no enumerable own-properties.
953953
"""
954-
if self.obj == None:
954+
if self.obj is None:
955955
return True
956956
if self._clean.isString():
957957
ret = self.obj.strip() is ""
@@ -1044,11 +1044,11 @@ def isCallable(self):
10441044
"""
10451045
Check if the given object is any of the function types
10461046
"""
1047-
return self._wrap(type(self.obj) is MethodType \
1048-
or type(self.obj) is FunctionType \
1049-
or type(self.obj) is LambdaType \
1050-
or type(self.obj) is BuiltinMethodType \
1051-
or type(self.obj) is BuiltinFunctionType\
1047+
return self._wrap(type(self.obj) is MethodType
1048+
or type(self.obj) is FunctionType
1049+
or type(self.obj) is LambdaType
1050+
or type(self.obj) is BuiltinMethodType
1051+
or type(self.obj) is BuiltinFunctionType
10521052
or type(self.obj) is UnboundMethodType)
10531053

10541054
def isFunction(self):
@@ -1322,7 +1322,7 @@ def template(self, data=None, settings=None):
13221322
Underscore templating handles arbitrary delimiters, preserves whitespace,
13231323
and correctly escapes quotes within interpolated code.
13241324
"""
1325-
if settings == None:
1325+
if settings is None:
13261326
settings = {}
13271327
ts = _.templateSettings
13281328
_.defaults(ts, self.templateSettings)
@@ -1391,7 +1391,7 @@ def escape(matchobj):
13911391
key = (matchobj.group(1).decode('string-escape')).strip()
13921392
return "' + _.escape(str(" + unescape(key) + " or '')) + '"
13931393

1394-
source = indent() + 'class closure:\n pass # for full closure support\n'
1394+
source = indent() + 'class closure(object):\n pass # for full closure support\n'
13951395
source += indent() + 'ns = closure()\n'
13961396
source += indent() + "ns.__p = ''\n"
13971397
#src = re.sub("^[\'\"]|[\'\"]$", "", ("%r" % src))
@@ -1403,7 +1403,7 @@ def escape(matchobj):
14031403

14041404
f = self.create_function(settings.get("variable") or "obj=None", source)
14051405

1406-
if data != None:
1406+
if data is not None:
14071407
return f(data)
14081408
return f
14091409

@@ -1415,7 +1415,7 @@ def create_function(self, args, source):
14151415
exec code in globals(), locals()
14161416
except:
14171417
print source
1418-
raise Exception("template error")
1418+
raise Exception("template error")
14191419
ns.func = func
14201420

14211421
def _wrap(obj={"this": ""}):

0 commit comments

Comments
 (0)