homepage

This issue tracker has been migrated to GitHub , and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author ncoghlan
Recipients Alexander.Belopolsky, Christophe Simonis, anacrolix, belopolsky, eckhardt, ironfroggy, jackdied, jcea, ncoghlan, r.david.murray, rhettinger, ssadler
Date 2013年10月24日.10:33:01
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1382610781.43.0.10906696951.issue4331@psf.upfronthosting.co.za>
In-reply-to
Content
To clarify the current state of this:
- I'm still in favour of adding this feature for Python 3.4
- a suitable patch is still needed, as the currently attached patches modify the existing functools.partial object, rather than adding a separate "partialmethod" API
- a Python implementation would be fine
The following prototype should work as a starting point to be elaborated into a full patch with docs and tests:
class partialmethod(functools.partial):
 def __get__(self, obj, cls):
 if obj is None:
 return self
 return functools.partial(self.func,
 *((obj,) + self.args),
 **self.keywords)
 def __call__(*args, **kwds):
 self, *args = args
 call_kwds = {}
 call_kwds.update(self.keywords)
 call_kwds.update(kwds)
 return self.func(self,
 *(self.args + args),
 **call_kwds)
class C:
 def example(self, *args, **kwds):
 print(self, args, kwds)
 fails = functools.partial(example, 1, 2, 3, x=1)
 works = partialmethod(example, 1, 2, 3, x=1)
>>> C().fails()
1 (2, 3) {'x': 1}
>>> C().works()
<__main__.C object at 0x7f91cefeea90> (1, 2, 3) {'x': 1}
>>> C().fails(4, 5, 6)
1 (2, 3, 4, 5, 6) {'x': 1}
>>> C().works(4, 5, 6)
<__main__.C object at 0x7f91cefeea10> (1, 2, 3, 4, 5, 6) {'x': 1}
History
Date User Action Args
2013年10月24日 10:33:01ncoghlansetrecipients: + ncoghlan, rhettinger, jcea, belopolsky, ironfroggy, jackdied, Christophe Simonis, ssadler, eckhardt, r.david.murray, Alexander.Belopolsky, anacrolix
2013年10月24日 10:33:01ncoghlansetmessageid: <1382610781.43.0.10906696951.issue4331@psf.upfronthosting.co.za>
2013年10月24日 10:33:01ncoghlanlinkissue4331 messages
2013年10月24日 10:33:01ncoghlancreate

AltStyle によって変換されたページ (->オリジナル) /