<html><head><style type="text/css" media="screen">Body{font-family: Verdana;font-size:.75em;}h4{font-size:.9em;}a{color: #3a62a6;}.digest .toc {margin-bottom: 15px; padding-bottom:8px; border-bottom: 1px solid #ccc;}.digest .tocItem {margin-bottom: 15px;}.tocItem a{color:#000;text-decoration: none;}.tocItem a:hover{color: #3a62a6;text-decoration: underline;}.topic{padding-bottom: 8px;margin-bottom: 20px; border-bottom: 1px solid #ccc;}.topicHeader{margin-bottom:10px;}.topicTitle{font-weight: bold;}.replies p{margin:0;padding:0;}.replies hr{width: 15%;text-align: left;margin: 0 auto 5px 0;border: none 0;border-top: 1px solid #ccc;height: 1px;}.reply{margin-bottom: 6px;padding-bottom: 4px;}.anchorMarker{color: #3a62a6;}.footer{color: gray;}</style></head><body><div class="digest"><p>Hi ironpython,</p><p>Here's your Daily Digest of new issues for project "<a href="http://ironpython.codeplex.com/">IronPython</a>".</p><p>In today's digest:</p><h4>ISSUES</h4><div class="toc"><div class="tocItem"><a href="#toc_issue_1">1. <span class="tocTitle">[New issue] builtin’s compile function inconsistent with CPython</span> <span class="anchorMarker">↓</span></a></div></div><h4>ISSUES</h4><div class="topic"><a name="toc_issue_1"></a><div class="topicHeader"><span class="topicTitle">1. [New issue] builtin’s compile function inconsistent with CPython</span> <a href="http://ironpython.codeplex.com/workitem/35707">view online</a></div><p>User TalSaiag has proposed the issue:</p><p>"When using compile to build an AST and then using it again to compile the code, the resulting object’s source is not set.<br />
Test function:<br />
<pre><code>def test():
    import ast
    PyCF_ONLY_AST = 1024
    PyCF_DONT_IMPLY_DEDENT = 512
    source = "def f():\n    return g()\ndef g():\n    x = 0\n    return 1 / x\nf()"
    cmp = compile(source, "<asd>", "exec", PyCF_ONLY_AST | PyCF_DONT_IMPLY_DEDENT, 1)
    index = 1 # g function only
    node = cmp.body[index]
    mod = ast.Module([node])
    code = compile(mod, "<asd2>", "exec")
    return code.co_filename, code.co_firstlineno
test()</code></pre>

In python the result should be: ('<asd2>', 3)<br />
In IronPython it’s: ('', 1)<br />
<br />
While trying to solve it myself, I found that the builtin’s compile (Modules\Builtin.cs:297) function doesn’t use the filename parameter given to the function in that case (while passing an AST as the source), and by passing it along to ConvertToPythonAst and in that function to the SourceUnit constructor instead of “” (Modules_ast.cs:72), the co_filename parameter is fixed.<br />
Fixing the location is not as easy, I realized that the Node.SetLoc function is not being called upon creating a new one in Revert functions (in _ast.cs thus the Span is not set) but I’m not familiar with the code that much to find the right place (or places) to call it and with which arguments and I also think that won’t be sufficient for some reason. I’m not even sure I’m in the right track to solve this…"</p></div><div class="footer"><p>You are receiving this email because you subscribed to notifications on CodePlex.</p><p>To report a bug, request a feature, or add a comment, visit <a href="http://ironpython.codeplex.com/workitem/list/basic">IronPython Issue Tracker</a>. You can <a href="http://ironpython.codeplex.com/subscriptions/workitem/project/edit">unsubscribe or change your issue notification settings</a> on CodePlex.com.</p></div></div></body></html>