[PyChecker-list] Re: [Python-checkins] python/dist/src/Lib ftplib.py,1.66,1.67

Barry Scott barry@barrys-emacs.org
Fri, 10 May 2002 10:47:47 +0100


Maybe if you see this pattern:

	if obj: ... obj.something ...

you may need to ignore if "something" is a string or file method to
reduce false positives further.

		Barry

> -----Original Message-----
> From: pychecker-list-admin@lists.sourceforge.net
> [mailto:pychecker-list-admin@lists.sourceforge.net]On Behalf Of Neal
> Norwitz
> Sent: 09 May 2002 15:37
> To: Jack Jansen
> Cc: Guido van Rossum; loewis@sourceforge.net;
> python-checkins@python.org; PyChecker
> Subject: [PyChecker-list] Re: [Python-checkins] python/dist/src/Lib
> ftplib.py,1.66,1.67
> 
> 
> Jack Jansen wrote:
> > 
> > On woensdag, mei 8, 2002, at 06:02 , Guido van Rossum wrote:
> > >> And in general I think it's unwise in Python to have an object that
> > >> tests false (because it's __len__ returns 0, in the case of this bug
> > >> report) but is still expected to do something. "if object:
> > >> do_something_with(object)" is fairly standard Python idiom.
> > >
> > > But it's a time bomb waiting to go off!  The correct code should read
> > > "if object is not None: do_something_with(object)".  There are lots of
> > > objects that (for better or for worse!) define __len__.  So beware.
> > 
> > Hmm. I hadn't noticed this (yet), but I wonder whether it's then
> > a good idea to let pychecker or so test for this, especially the
> > case where an optional argument is used in a simple "if arg:"
> > test. I know that I wrote a lot of code like this over the
> > years...
> 
> There is a feature request for pychecker to do this:
> https://sourceforge.net/tracker/index.php?func=detail&aid=530528&group_id=24686&atid=382220
> 
> I haven't done anything because I think there would
> be too many false positives.  Is there a set of rules
> which would indicate when this is dangerous?  Of course,
> the rules would also eliminate cases which should be ok.
> 
> Neal
> 
> _______________________________________________________________
> 
> Have big pipes? SourceForge.net is looking for download mirrors. We supply
> the hardware. You get the recognition. Email Us: bandwidth@sourceforge.net
> _______________________________________________
> PyChecker-list mailing list
> PyChecker-list@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/pychecker-list
>