type annotation vs working code

Richard Damon Richard at Damon-Family.org
Sun Oct 1 14:33:21 EDT 2023


My view of the issue is that the "trick" of "evaluating" a name to see 
if the object has been initialized is just a tad on the "tricky" side, 
and the annotation/value is really incorrect.

The name at the point you are annotating it, isn't really a "bool" 
because a bool will always have either the value "True" or "False", 
while for this variable, you are really testing if it exists or not.

Perhaps a better method would be rather than just using the name and 
catching the exception, use a real already_initialized flag (set to True 
when you initialize), and look it up with getattr() with a default value 
of False.

-- 
Richard Damon



More information about the Python-list mailing list