[wingide-users] method completion
Walker Hale
walkerh at picoscript.com
Mon Mar 13 11:36:02 EST 2006
The "if 0" part of the idiom restores duck typing. The assertion is not
actually run at runtime, since 0 is always construed as false. It just
serves to tell the Wing about the type of the object. (It may also insert a
tiny amount of unused byte code into your compiled files.)
This idiom is also in the Wing docs. It is a Good Thing (tm). If you need
it, use it.
if 0:
assert isinstance( myObject, theType )
Walker
-----Original Message-----
From: wingide-users-bounces at wingware.com
[mailto:wingide-users-bounces at wingware.com] On Behalf Of ybastide
Sent: Monday, March 13, 2006 9:14 AM
To: Martijn Pieters
Cc: wingide-users at wingware.com
Subject: Re: [wingide-users] method completion
Martijn Pieters wrote:
> ybastide wrote:
>> Yep, there's a standard idiom::
>>
>> if 0:
>> assert isinstance(self.logger, Logger)
>
> No need to hide the statement in a if 0; assertions are, if your code
> is correct, harmless.
I disagree: asserting isinstance's prevents duck typing.
> You can also instruct Python to not even compile assertions (the only
> difference between 'optimized' and nonoptimized python bytecode).
Yep, and this is generally a Bad Thing (as you said, assertions should be
correct)
>
> Martijn Pieters
yves
_________________________________________________
Wing IDE users list
http://wingware.com/lists/wingide
--
No virus found in this incoming message.
Checked by AVG Free Edition.
Version: 7.1.375 / Virus Database: 268.2.1/279 - Release Date: 3/10/2006
--
No virus found in this outgoing message.
Checked by AVG Free Edition.
Version: 7.1.375 / Virus Database: 268.2.1/279 - Release Date: 3/10/2006
More information about the wingide-users
mailing list