Message319692
Oh, I see, you want to be able to get the source for code entered into the interactive session.
IPython does this by creating a separate fake "file name" for every input and adding corresponding entries for them into `linecache.cache'. This doesn't work for classes 'cuz for them, inspect.getfile() rather looks at __module__.__file__ , and there's no single __file__ for __main__.
Now, there are two concerns here:
* This will lead to linecache being polluted with old input, effectively a memory leak. Unlike vanilla's readline cache which has a maximum length. Not much concern for IPython which only needs to be good enough for its target audience and can be dropped if it doesn't work for a specific scenario. But not for vanilla which needs to work reliably in all cases.
* There indeed is a discrepancy between functions that link to source directly and classes that rely on heuristics for that (inspect.findsource() searches the file with a regex for the class' definition, how absurd is that?). Adding __file__ and __firstlineno__ _could_ help here, the `class' directive will need to add them.
* In any case, the returned source is prone to "not necessarily what the interpreter uses", but that's the problem with how the returned source is generated, not where it's taken from. |
|
Date |
User |
Action |
Args |
2018-06-15 23:36:26 | Ivan.Pozdeev | set | recipients:
+ Ivan.Pozdeev, t-vi |
2018-06-15 23:36:26 | Ivan.Pozdeev | set | messageid: <1529105786.78.0.56676864532.issue33826@psf.upfronthosting.co.za> |
2018-06-15 23:36:26 | Ivan.Pozdeev | link | issue33826 messages |
2018-06-15 23:36:26 | Ivan.Pozdeev | create | |
|