“编译时间”检查? [英] "Compile time" checking?

查看:84
本文介绍了“编译时间”检查?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,


我是Python的新手,我正在试图弄清楚如何获得这个代码编译的b / b
? 类似代码检查。对我来说,这是一个非常基本的语言/环境要求,特别是在处理大型的
项目时。在编译时捕获错误要好得多*。相比

比运行时更好。


有一件事我已经发现了是PyChecker模块(方便地在SPE中嵌入

),但它似乎没有做那么好的工作。例如,

以下简单程序就PyChecker

而言完美检查:


#----

def测试仪(a,b,c):

打印伪测试功能,a,b,c

测试仪(1 ,2,3)#this运行正常

tester(1,2)#这显然导致运行时TypeError异常

#----


在我看来,对于PyChecker来说,这应该是一个明显的问题。我想b / b
假设你可能会说你不希望PyChecker咆哮你

任何时候因为你可能会故意提出异常

引起异常,但这个看起来非常简单明了一个

要抓住。


我的问题是:

- 我的测试器示例是否遗漏了什么?

- 除了PyChecker之外还有其他代码检查选项吗?


其他任何评论都赞赏(除了比如恰到好处

代码没有那样的bug:)。


谢谢!

Hi there,

I''m pretty new to Python and am trying to figure out how to get "will
this code compile?"-like code checking. To me this is a pretty basic
language/environment requirement, especially when working with large
projects. It is *much* better to catch errors at "compile-time" rather
than at run-time.

One thing I''ve "found" is the PyChecker module (conveniently embedded
in SPE), but it doesn''t seem to do that great of a job. For example,
the following simple program checks out perfectly as far as PyChecker
is concerned:

#----
def tester(a,b,c):
print "bogus test function",a,b,c
tester(1,2,3) #this runs fine
tester(1,2) #this obviously causes a run-time TypeError exception
#----

It seems to me that this should be an obvious catch for PyChecker. I
suppose you could argue that you don''t want PyChecker to bark at you
any time an exception would be raised since you may intentionally be
causing exceptions, but this one seems a pretty simple and obvious one
to catch.

My questions are:
- Am I missing something with my tester example?
- Are there other code-checking options other than PyChecker?

Any other comments appreciated (aside from things like "just right good
code that doesn''t have bugs like that" :) ).

Thanks!

推荐答案

Qopit写道:
Qopit wrote:
[snip]

我的问题是:<我错过了我的测试器示例吗?
- 除了PyChecker之外还有其他代码检查选项吗?
[snip]

My questions are:
- Am I missing something with my tester example?
- Are there other code-checking options other than PyChecker?




尝试pylint


-

Benjamin Niemann

电子邮件:粉红色at odahoda dot de

WWW: http:/ /www.odahoda.de/


2005年8月10日08:53:15 -0700,Qopit< ru ******** ****@gmail.com>写道:
On 10 Aug 2005 08:53:15 -0700, Qopit <ru************@gmail.com> wrote:
你好,

我是Python的新手,我想弄清楚如何获得将这段代码编译好吗? ; -like代码检查。
Hi there,

I''m pretty new to Python and am trying to figure out how to get "will
this code compile?"-like code checking.




为什么不通过尝试编译来找出它? :-)

-

电邮:zen19725 at zen dot co dot uk



Why not just find out, by trying to compile it? :-)
--
Email: zen19725 at zen dot co dot uk


2005年8月10日08 :53:15 -0700

Qopit写道:
On 10 Aug 2005 08:53:15 -0700
Qopit wrote:
def tester(a,b,c):
print"伪造测试功能" ,a,b,c
测试人员(1,2,3)#this运行良好
测试人员(1,2)#这显然导致运行时TypeError异常
def tester(a,b,c):
print "bogus test function",a,b,c
tester(1,2,3) #this runs fine
tester(1,2) #this obviously causes a run-time TypeError exception




/ tmp%cat> a.py

def tester(a,b,c):

print" bogus test function" ,a,b,c

tester(1,2,3)#this运行良好

tester(1,2)#这显然会导致运行时TypeError异常

/ tmp%pychecker a.py

处理...

伪测试功能1 2 3

捕获异常导入模块a:

文件" /usr/lib/site-python/pychecker/checker.py",第587行,在setupMainCode()中

module = imp.load_module(self.moduleName,file,filename,smt)

文件" a.py",第4行

tester(1,2)#this显然导致运行时TypeError异常

TypeError:tester()正好接受3个参数(2个给定)


警告......


a:1:未处理无法进口

/ tmp%pychecker -V

0.8。 14

-

jk



/tmp% cat >a.py
def tester(a,b,c):
print "bogus test function",a,b,c
tester(1,2,3) #this runs fine
tester(1,2) #this obviously causes a run-time TypeError exception
/tmp% pychecker a.py
Processing a...
bogus test function 1 2 3
Caught exception importing module a:
File "/usr/lib/site-python/pychecker/checker.py", line 587, in setupMainCode()
module = imp.load_module(self.moduleName, file, filename, smt)
File "a.py", line 4
tester(1,2) #this obviously causes a run-time TypeError exception
TypeError: tester() takes exactly 3 arguments (2 given)

Warnings...

a:1: NOT PROCESSED UNABLE TO IMPORT
/tmp% pychecker -V
0.8.14

--
jk


这篇关于“编译时间”检查?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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