[Python-ideas] Better Type Hinting
Thomas Güttler
guettliml at thomas-guettler.de
Fri Jun 5 15:32:36 CEST 2015
Am 05.06.2015 um 10:38 schrieb Andrew Barnert:
> On Jun 5, 2015, at 00:21, Thomas Güttler <guettliml at thomas-guettler.de> wrote:
>>
>>> Am 05.06.2015 um 08:19 schrieb Stephen Hansen:
>>>> On Thu, Jun 4, 2015, at 11:01 PM, Andrew Barnert via Python-ideas wrote:
>>>> On Jun 4, 2015, at 22:36, Thomas Güttler <guettliml at thomas-guettler.de>
>>>> wrote:
>>>>>
>>>>> It would be great to have better type hinting in IDEs.
>>>>
>>>> Is PEP 484 not sufficient for this purpose?
>>>
>>> It's really not.
>>>
>>> For one thing, PEP 484 isn't going to result in the standard library
>>> being hinted all up (though I assume someone may make stubs). But
>>> really, the specific issue that the OP is running into is because of the
>>> signature of logging.warn -- msg, *args, **kwargs.
>>
>> I am using logger.warn() not logging.warn().
>>
>> The question is: How to know which kind of duck "logger" is?
>
> That is _exactly_ what PEP 484 addresses.
Now I read it and it does exactly what I was looking for.
> If `logging.getLogger` is annotated or stubbed to specify that it returns a `logging.Logger` (which it will be),
> then a static type checker (whether MyPy or a competing checker or custom code in the IDE)
> can trivially infer that `logger` is a `logging.Logger`.
Unfortunately we still use Python2.7, but maybe it is time for change ...
Just one thing left:
> **If** `logging.getLogger` is annotated ....
What is the policy of the standard library? Will there be type hints
for methods like logging.getLogger() in the standard library in the future?
Since it is quite easy to add them, will patches be accepted?
Regards,
Thomas Güttler
More information about the Python-ideas
mailing list