Am 12.08.16 um 11:58 schrieb BartC:
On 12/08/2016 10:45, Chris Angelico wrote:
On Fri, Aug 12, 2016 at 7:38 PM, BartC <b...@freeuk.com> wrote:
You can be too dynamic. Take an example like this:

 d.yaer=1999

 print (d.day,d.month,d.year)

This would never get past a static language nor some that also have
dynamic
types.

Nor will it get past a lot of linters. Or unit tests. There are other
solutions.

How would a linter know that you didn't /want/ to create a new attribute
called 'yaer'?

It is possible to create an attribute outside of the class, but it is unusual. I tried your example using pylint. It gives me:

W: 9, 0: Attribute 'yaer' defined outside __init__ (attribute-defined-outside-init)

Granted, pylint also spits an enormous amount of other stylistic warnings about spaces and "wrong" indents which, strangely, have the same weight "warning" as this bug, so it's a bit hard to find.

A linter from another language I use also spell-checks variable names, i.e. if it finds two variables with suspiciously similar names, it reports it. Of course the linter never knows for sure, it can only give warnings.

        Christian
--
https://mail.python.org/mailman/listinfo/python-list

Reply via email to