Skip to content

Commit

Permalink
#6 tests pass y'all
Browse files Browse the repository at this point in the history
  • Loading branch information
Cory Dodt committed Sep 12, 2018
1 parent 2ca7c56 commit f92d46d
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions codado/py.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@
from crosscap.doc import Documentation as _Documentation, doc as _doc


if hasattr(inspect, 'getfullargspec'): # pragma: nocover
getargspec = inspect.getfullargspec
else: # pragma: nocover
getargspec = inspect.getargspec


EMOJI = u'👻👾🤖😼💫👒🎩🐶🦎🐚🌸🌲🍋🥝🥑🥐🍿🥄⛺🚂🚲🌈🏆🎵💡✏🖍📌🛡♻'


Expand Down Expand Up @@ -49,12 +55,20 @@ def eachMethod(decorator, methodFilter=lambda fName: True):
prefix = methodFilter
methodFilter = lambda fName: fName.startswith(prefix)

ismethod = lambda fn: inspect.ismethod(fn) or inspect.ismethoddescriptor(fn)
ismethod = lambda fn: inspect.ismethod(fn) or inspect.isfunction(fn)

def innerDeco(cls):
assert inspect.isclass(cls), "eachMethod is designed to be used only on classes"
for fName, fn in inspect.getmembers(cls):
if ismethod(fn) and methodFilter(fName):
setattr(cls, fName, decorator(fn))
if methodFilter(fName):
if ismethod(fn):
# We attempt to avoid decorating staticmethods by looking for an arg named cls
# or self; this is a kludge, but there's no other way to tell, and
# staticmethods do not work correctly with eachMethod
if getargspec(fn).args[0] not in ['cls', 'self']:
continue

setattr(cls, fName, decorator(fn))

return cls
return innerDeco
Expand Down

0 comments on commit f92d46d

Please sign in to comment.