[Python-ideas] String Format Callable Flag (Was: Efficient Debug Logging)

Pavol Lisy pavol.lisy at gmail.com
Sun Feb 19 04:23:31 EST 2017

On 2/19/17, Eric V. Smith <eric at trueblade.com> wrote:
> On 2/18/2017 2:25 AM, Steven D'Aprano wrote:

>> I see three problems:
>> (1) It will be a bug magnet. People will accidently write
>>     logging.debug('%03d %C03d', 1, expensive())
>> and then not only will their code still be slow, but they'll have to
>> debug mysterious
>>     TypeError: 'int' object is not callable
>> exceptions, but only *sometimes*. Most insideously, these Heisenbugs
>> will only occur when they turn the log level all the way up to
>> debugging, which will crash their program *before* logging the error!
> I think this is lessened with my proposal to use !c, but it's definitely
> still an issue. Test your logging!

1. I think that error message could be understandable at least as this:
    ValueError: Unknown format code 'g' for object of type 'str'

with something like isinstance(arg, callable)

2. Static checker could check bracket presence if there is !c format
specifier and fire warning.

3. There could be another problem if return type is callable too...

More information about the Python-ideas mailing list