[Python-ideas] Better Type Hinting

Cory Benfield cory at lukasa.co.uk
Fri Jun 5 09:36:18 CEST 2015


> On 5 Jun 2015, at 08:21, Thomas Güttler <guettliml at thomas-guettler.de> wrote:
> 
> I am using logger.warn() not logging.warn().
> 
> The question is: How to know which kind of duck "logger" is?
> 
> "logger" was created by "logging.getLogger(__name__)"
> 
> It is not the question how to implement better guessing in the IDE.
> 
> The basics needs to be solved. Everything else is "toilet paper programming"
> (Ah, smell inside, ... let's write an wrapper ...)

This question is unanswerable unless you actually execute the code at runtime under the exact same conditions as you expect to encounter it.

Because Python allows for monkey patching at runtime by any other code running in the process you can make no assumptions about what kind of duck that will be. Even without monkey patching you can’t know, because someone may have adjusted sys.path ahead of time, causing you to import an entirely unexpected module called ‘logging’.

In certain specialised cases, if you limit yourself to special rules, you *might* be able to statically assert the type of this object, but in the general case it simply cannot be done.

So the only way to improve this is to implement better guessing in the IDE. Hence the improvements that were proposed to you.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 801 bytes
Desc: Message signed with OpenPGP using GPGMail
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20150605/b4493225/attachment.sig>


More information about the Python-ideas mailing list