Skip to content

Commit

Permalink
ENH: __name__ doesn't respect descriptor protocol on class
Browse files Browse the repository at this point in the history
  • Loading branch information
llllllllll committed Aug 20, 2015
1 parent 4548799 commit eebc418
Showing 1 changed file with 11 additions and 15 deletions.
26 changes: 11 additions & 15 deletions toolz/functoolz.py
Original file line number Diff line number Diff line change
Expand Up @@ -609,21 +609,17 @@ def __call__(self, *args, **kwargs):
except self.exc:
return self.default()

@object.__new__
class __name__(object):
def __get__(self, instance, owner):
if instance is None:
return 'excepts'

exc = instance.exc
try:
if isinstance(exc, tuple):
exc_name = '_or_'.join(map(attrgetter('__name__'), exc))
else:
exc_name = exc.__name__
return '%s_excepting_%s' % (instance.f.__name__, exc_name)
except AttributeError:
return 'excepting'
@property
def __name__(self):
exc = self.exc
try:
if isinstance(exc, tuple):
exc_name = '_or_'.join(map(attrgetter('__name__'), exc))
else:
exc_name = exc.__name__
return '%s_excepting_%s' % (self.f.__name__, exc_name)
except AttributeError:
return 'excepting'

@partial(lambda a, b=__doc__: a(b)) # close over the class __doc__
class __doc__(object):
Expand Down

0 comments on commit eebc418

Please sign in to comment.