Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #105731 > unrolled thread

How to make Python interpreter a little more strict?

Started byAleksander Alekseev <afiskon@devzen.ru>
First post2016-03-25 15:06 +0300
Last post2016-03-26 23:00 +1100
Articles 2 — 2 participants

Back to article view | Back to comp.lang.python


Contents

  How to make Python interpreter a little more strict? Aleksander Alekseev <afiskon@devzen.ru> - 2016-03-25 15:06 +0300
    Re: How to make Python interpreter a little more strict? Steven D'Aprano <steve@pearwood.info> - 2016-03-26 23:00 +1100

#105731 — How to make Python interpreter a little more strict?

FromAleksander Alekseev <afiskon@devzen.ru>
Date2016-03-25 15:06 +0300
SubjectHow to make Python interpreter a little more strict?
Message-ID<mailman.21.1458986315.28225.python-list@python.org>
Hello

Recently I spend half an hour looking for a bug in code like this:

eax@fujitsu:~/temp$ cat ./t.py 
#!/usr/bin/env python3

for x in range(0,5):
    if x % 2 == 0:
        next
    print(str(x))

eax@fujitsu:~/temp$ ./t.py 
0
1
2
3
4

Is it possible to make python complain in this case? Or maybe solve
such an issue somehow else?

-- 
Best regards,
Aleksander Alekseev
http://eax.me/

[toc] | [next] | [standalone]


#105751

FromSteven D'Aprano <steve@pearwood.info>
Date2016-03-26 23:00 +1100
Message-ID<56f679cb$0$1611$c3e8da3$5496439d@news.astraweb.com>
In reply to#105731
On Fri, 25 Mar 2016 11:06 pm, Aleksander Alekseev wrote:

> Is it possible to make python complain in this case? Or maybe solve
> such an issue somehow else?

This is a job for a "linter", such as pychecker, pylint or pyflakes. Google
for more if you are interested.

A linter will check your code for things which are *legal* code, but might
not do what you expect, or are a sign of a potential error. For instance,
dead code that will never be reached, or variables that are defined and
then never used, or functions (such as next) which are named but not used.

Another thing you can do is use an editor which colours functions
like "next" differently from statements like "continue".



-- 
Steven

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web