Why no warnings when re-assigning builtin names?

Terry Reedy tjreedy at udel.edu
Wed Aug 17 04:10:30 CEST 2011


On 8/16/2011 7:49 PM, Seebs wrote:
> On 2011-08-16, Terry Reedy<tjreedy at udel.edu>  wrote:
>> On 8/16/2011 2:56 PM, Seebs wrote:
>>> I wonder whether there's a way to mitigate the cost of these things by
>>> messing with -W settings, such that runtime that wants to be fast can
>>> omit the checks, but the default could still be to, well, prevent likely
>>> errors.
>
>> Warning messages have a cost even if suppressed.
>
> Yes, but is it a *significant* cost?  My assumption is that the suppression
> would be of checking, not just of displaying messages.

The -W settings suppress display or printing of warnings, not their 
generation.

import warnings

if some_condition:
   warnings.warn(message, Warning)

The test and warn call are made regardless of disposition. Filters 
determine what is done with each Warning subclass. The logging module 
can grab them too.

-- 
Terry Jan Reedy




More information about the Python-list mailing list