本文介绍了IronPython compile()不接受AST对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在说明文件中,源"可以是str或AST对象

In the documentation it says, 'source' can be either str or AST object

当尝试编译我的ast根时:

When trying to compile my ast root:

dl = compile(newRoot, '<string>', 'eval')

我收到此异常:

expected str, got Module

我正在使用IronPython的最新版本.

I am using the last version of IronPython.

有没有一个想法为什么不起作用?我发现的所有示例似乎都是以这种方式完成的.

Is there an idea why this does not work? all the examples I found seem to do it this way with no issues.

是否有解决方法来编译AST对象?

Is there a workaround to compile an AST object?

谢谢!!!!

PD:我发现了此问题,但似乎没有任何活动: http://ironpython.codeplex.com /workitem/32526

PD: I found this issue but seems to have no activity: http://ironpython.codeplex.com/workitem/32526

推荐答案

首先,IronPython不支持此功能.

First off, IronPython does not support this.

实际上很难在IronPython中支持(直到今天我才知道它需要得到支持). IronPython的_ast模块是其自身AST的包装,并且当前仅实现从IronPython AST => CPython AST的转换,但不是反向转换.这是一件相当(诚实,非常乏味)的工作,所以我不确定什么时候可以解决.

It's actually quite hard to support in IronPython (and I didn't know it needed to be supported until today). IronPython's _ast module is a wrapper around its own AST, and currently only implements conversion from IronPython AST => CPython AST, but not the reverse. It's a fair bit of (honestly, quite tedious) work, so I'm not sure when it will get fixed.

如果有一个流行的程序或库因此而被破坏,从而将其移到优先级列表中,那么总是欢迎使用补丁程序.

If there's a popular program or library that's broken because of this that moves it up the priority list, and patches are always welcome.

这篇关于IronPython compile()不接受AST对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-13 18:27