On 3/30/06, Terry Reedy <[EMAIL PROTECTED]> wrote:
>
> "Aahz" <[EMAIL PROTECTED]> wrote in message
> news:[EMAIL PROTECTED]
> > What do we want to tell people who have code like this:
> >
> > keys = d.keys()
> > keys.sort()
>
> Could a good-enough code analyzer detect such, even if separated by
> intervening lines? If so, it could suggest sorted() as a fix. I wonder if
> the pypy analyzer could be adapted for 2.x to 3.0 warning and upgrade
> purposes. Or do pylint or pychecker gather enough information?
pychecker is supposed to have this info, but only if d is known to be
a dict. It could be extended to assume any method keys() (and
friends) should return iterators. In which case, it would say that an
iterator doesn't have a sort method. Below is the output of the
current version.
n
### file: tt.py
def foo():
d = {}
keys = d.keys()
keys.sort()
keys.sort2()
###
$ pychecker tt.py
Processing tt...
Warnings...
tt.py:6: Object (keys) has no attribute (sort2)
_______________________________________________
Python-3000 mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-3000
Unsubscribe:
http://mail.python.org/mailman/options/python-3000/archive%40mail-archive.com