[Python-ideas] Better Type Hinting
Nick Coghlan
ncoghlan at gmail.com
Fri Jun 5 16:53:27 CEST 2015
On 5 Jun 2015 23:34, "Thomas Güttler" <guettliml at thomas-guettler.de> wrote:
>
>
>
> 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 ...
The typeshed project provides stubs for both Python 2 & 3:
<https://github.com/JukkaL/typeshed>https
<https://github.com/JukkaL/typeshed>:// <https://github.com/JukkaL/typeshed>
github.com <https://github.com/JukkaL/typeshed>/
<https://github.com/JukkaL/typeshed>JukkaL
<https://github.com/JukkaL/typeshed>/ <https://github.com/JukkaL/typeshed>
typeshed <https://github.com/JukkaL/typeshed>
Type hinting your own code where appropriate would be easier in Python 3
(since you can use inline type hints)
> 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?
The standard library won't be getting native annotations any time soon, but
the typeshed annotations are expected to fill the gap.
> Since it is quite easy to add them, will patches be accepted?
Contributions to the typeshed stubs would be preferable.
Cheers,
Nick.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20150606/1019b1aa/attachment.html>
More information about the Python-ideas
mailing list