pychecker之后的下一步 [英] Next step after pychecker

查看:87
本文介绍了pychecker之后的下一步的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述






我想开发一个比pychecker更进一步的工具

以确保python程序有效性。我们的想法是接近人们在ocaml上获得的结果:对所有类型的

程序进行静态验证,没有任何变量声明。这肯定会给
带来很多功能。


想法是分析整个程序,确定对
$ b $的限制b函数参数并检查这些约束是否由程序的其他部分验证。


您认为实现此目的的最佳工具是什么?我对pychecker有一个广泛的看法,它肯定可以扩展为

这个工作。仍然关注我的是它在字节码上工作,

阻止它使用jython和新的.NET python。


我目前阅读有关AST和访客的文档,但我不确定这是否也是最好的工具。 AST看起来相当深刻,我担心它会让分析变得非常缓慢而且很复杂。

对于一个简单的模式我想这样做:


def f1(a):

返回+ 1


def f2( ):

f1([])


显然,这不行,但pychecker和python都没有

口译员会抓住它。但是程序分析可以在这个

简单示例中找到它。


问候,


Philippe

解决方案

Philippe Fremy< ph ** @freehackers.org>写道:

我想开发一个比pychecker更进一步的工具,以确保python程序的有效性。我们的想法是让人们接近人们对ocaml的看法:对程序的所有类型进行静态验证,而不需要任何变量声明。这肯定会给python带来很大的力量。




你知道,我一直认为ML风格的类型推断是一个

令人印象深刻的技术壮举,但为什么不使用

声明这么重要?这是我从未真正理解过的一个方面。


Philippe Fremy写道:

我想开发一个步骤比pychecker更进一步确保python程序的有效性。我们的想法是接近人们对ocaml的看法:对所有类型的程序进行静态验证,没有任何变量声明。这绝对会给python带来很大的力量。


这是一个非常酷的想法,并且有人谈论在
Python 3.0中加入这样的工具,尽管如此,没有人自愿参与解决这个问题。

=)请注意,你实际上并不能真正确保程序的有效性,但是你可以做一些像pychecker那样有根据的猜测。一个例子:


def f1(a):

返回+ 1


def f2():

返回f1([])


您的建议是该代码应被视为无效。但如果

后面跟着:


f1 =''''。join

f2()


其中f1反弹,那么它是完全有效的代码。那就是说,我认为

提供建议像pychecker一样绝对值得追求。

您认为什么是实现这一目标的最佳工具?我对pychecker进行了广泛的研究,它当然可以扩展到这项工作。仍然与我有关的事情是它在字节码上工作,
阻止它使用jython和新的.NET python。


我不太了解pychecker的功能,但是如果它与

字节码一起工作,对jython来说不​​应该没问题IronPython的?我认为

字节码是语言规范的一部分,CPython具体是什么

是字节码实际实现的方式......

我目前正在阅读关于AST和访问者的文档,但我不确定这将是最好的工具。 AST看起来很深,我担心它会使分析变得非常缓慢而且复杂。




你应该读一下最近python-dev讨论合并

AST分支。我不太了解它,但显然目前正在做一些关于如何在Python中使用AST的工作。对不起

我不太了解这个...

Steve


Paul Rubin写道:< blockquote class =post_quotes> Philippe Fremy< ph ** @ freehackers.org>写道:

我想开发一个比pychecker更进一步的工具,以确保python程序的有效性。我们的想法是让人们接近人们对ocaml的看法:对程序的所有类型进行静态验证,而不需要任何变量声明。这肯定会给python带来很大的威力。



你知道,我一直认为ML风格的类型推断是一个令人印象深刻的技术壮举,但为什么不使用
声明这么重要?这是我从未真正理解过的一个方面。




你知道,我认为我同意;-)。仅仅因为你没有宣布类型,

并不意味着你无论如何都可以改变隐含的类型。无论如何,对于更复杂的程序,最低价格为
。事实上,当你想做这样的事情时,对于
进行类型检查会更安全。我目前需要将数字参数更改为字符串参数
(找出

order_no不仅仅是规格指定的数字)。当然这个

参数正在很多地方使用。更改它有点可怕,因为我们必须确保它在整个代码中的任何地方都没有被视为数字

。是单位测试的良好覆盖率

有帮助,但不幸的是我们还没有很好的覆盖率。作为初学者,TDD很难实现。


干杯,


Huy


Hi,

I would like to develop a tool that goes one step further than pychecker
to ensure python program validity. The idea would be to get close to
what people get on ocaml: a static verification of all types of the
program, without any kind of variable declaration. This would definitely
brings a lot of power to python.

The idea is to analyse the whole program, identify constraints on
function arguments and check that these constraints are verified by
other parts of the program.

What is in your opinion the best tool to achieve this ? I had an
extensive look at pychecker, and it could certainly be extended to do
the job. Things that still concern me are that it works on the bytecode,
which prevents it from working with jython and the new .NET python.

I am currently reading the documentation on AST and visitor, but I am
not sure that this will be the best tool either. The AST seems quite
deep and I am afraid that it will make the analysis quite slow and
complicated.
For a simple pattern of what I want to do:

def f1( a ):
return a+1

def f2():
f1( [] )

Obviously, this won''t work, but neither pychecker nor the python
interpreter will catch it. But a program analysis can catch it in this
simple example.

regards,

Philippe

解决方案

Philippe Fremy <ph**@freehackers.org> writes:

I would like to develop a tool that goes one step further than
pychecker to ensure python program validity. The idea would be to get
close to what people get on ocaml: a static verification of all types
of the program, without any kind of variable declaration. This would
definitely brings a lot of power to python.



You know, I''ve always thought that ML-style type inference is an
impressive technical feat, but why is it so important to not use
declarations? This is an aspect I''ve never really understood.


Philippe Fremy wrote:

I would like to develop a tool that goes one step further than pychecker
to ensure python program validity. The idea would be to get close to
what people get on ocaml: a static verification of all types of the
program, without any kind of variable declaration. This would definitely
brings a lot of power to python.
It''s a very cool idea, and there was talk of including such a tool in
Python 3.0, though as yet, no one has volunteered to solve this problem.
=) Note that you can''t actually really ensure program validity, but you
can make some educated guesses like pychecker does. An example:

def f1(a):
return a + 1

def f2():
return f1([])

Your suggestion was that this code should be deemed invalid. But if
it''s followed with:

f1 = ''''.join
f2()

where f1 is rebound, then it''s perfectly valid code. That said, I think
providing "suggestions" like pychecker does is definitely worth pursuing.
What is in your opinion the best tool to achieve this ? I had an
extensive look at pychecker, and it could certainly be extended to do
the job. Things that still concern me are that it works on the bytecode,
which prevents it from working with jython and the new .NET python.
I don''t know much about what pychecker does, but if it works with the
bytecode, shouldn''t it be fine for jython and IronPython? I thought the
bytecode was part of the language spec, and what was CPython specific
was how the bytecodes were actually implemented...
I am currently reading the documentation on AST and visitor, but I am
not sure that this will be the best tool either. The AST seems quite
deep and I am afraid that it will make the analysis quite slow and
complicated.



You should read up on the recent python-dev discussions about merging
the AST branch. I don''t know too much about it, but apparently there''s
some work being done currently on how the AST is used in Python. Sorry
I don''t know more about this...
Steve


Paul Rubin wrote:

Philippe Fremy <ph**@freehackers.org> writes:

I would like to develop a tool that goes one step further than
pychecker to ensure python program validity. The idea would be to get
close to what people get on ocaml: a static verification of all types
of the program, without any kind of variable declaration. This would
definitely brings a lot of power to python.


You know, I''ve always thought that ML-style type inference is an
impressive technical feat, but why is it so important to not use
declarations? This is an aspect I''ve never really understood.



You know, I think I agree ;-). Just because you don''t declare the types,
doesn''t mean you can change the implicit type willy nilly anyway; at
least for more complex programs anyway. In fact, it would be safer to
have type checking when you want to do something like this. I currently
needed to change a number parameter to a string parameter (found out
order_no wasn''t just numbers as specs had specified). Of course this
parameter was being used in a great many places. Changing it was a bit
scary because we had to make sure it wasn''t being treated as a number
anywhere throughout the code. Yes good coverage with unit tests would
have helped but unfortunately we do not yet have good coverage. TDD is a
quite hard to practice as a beginner.

Cheers,

Huy


这篇关于pychecker之后的下一步的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆