[Python-ideas] "old" values in postconditions
leewangzhong+python at gmail.com
Tue Sep 25 14:20:06 EDT 2018
Ah. It wasn't clear to me from the thread that James was using `inspect`.
As it happens, not only does getsource give more than it should, it
also gives less than it should. The following bug still exists in
3.6.1. It was closed as a wontfix bug back in Python 2 because, I
presume, fixing it would require changing code objects.
Regardless, I think it'd be better not to rely on such magic for the
proposal. While it's a fun puzzle, whether it's possible or not, it
still modifies the syntax and/or scoping and/or evaluation order rules
On Tue, Sep 25, 2018 at 1:54 PM Marko Ristin-Kaufmann
<marko.ristin at gmail.com> wrote:
> Hi James and Franklin,
> getsource() definitely does not work. I tried for a long, long time to make it work and finally gave up. I parse in icontract the whole file where the lambda function resides and use asttokens to locate the node of the lambda (along some tree traversing upwards and making assumptions where the condition lambda lives).
> Have a look at:
> On Tue, 25 Sep 2018 at 19:48, James Lu <jamtlu at gmail.com> wrote:
>> > I'm surprised you haven't found
>> > inspect.getsource(func)
>> I did. That’s exactly what I was describing in the paragraph. It wouldn’t work in interactive mode and it includes everything on the same line of the lambda definition.
>> Python-ideas mailing list
>> Python-ideas at python.org
>> Code of Conduct: http://python.org/psf/codeofconduct/
More information about the Python-ideas