Re: Python static type checking

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




On 12/03/19 23:34, Gregory Farnum wrote:
> We talked about this briefly in the testing weekly last week and it
> looks pretty cool to me! As a C++ developer dabbling in Python, I've
> had periodic trouble dealing with dynamic typing (o_0) and the extra
> tests we could add against PRs seem real nice.
> 
> Unfortunately mypy is apparently pretty noisy and has a number of
> false positives if you *don't* add the annotations, so we can't just
> use it for free.
> 
> How do people feel about adding those annotations to our coding
> standards and enforcing rules on PRs about not adding warnings?
> Perhaps we could try it out in just the mgr, or one of the modules, if
> we feel like we need some experience with the tradeoffs?

I like the idea and I think we should at the same time remove the
python2 support, and start using python3.6 type annotations. This allows
to avoid to write type annotations inside code comments.

> -Greg
> 
> On Mon, Mar 4, 2019 at 1:17 AM Sebastian Wagner <swagner@xxxxxxxx> wrote:
>>
>> all,
>>
>> to find bugs in our Python code base a bit earlier, I looked into static
>> type checking using mypy and I'd like to share my results.
>>
>> Mypy ( http://mypy-lang.org/ ) is a static type checker for Python that
>> aims to combine the benefits of dynamic (or "duck") typing and static
>> typing.
>>
>> As of now, running mypy on our code base already reveals some genuine
>> bugs, especially with respect to Python 3 incompatibilities.
>>
>> Unfortunately, we will need to look into every module and message and
>> manually separate bugs and false-positives.
>>
>> Here are two example errors:
>>
>>> pybind/mgr/restful/decorators.py:21: error:
>>>   Argument 1 to "split" of "bytes" has incompatible type "str"; expected "Optional[bytes]"
>>
>>
>> This is an issue that will be fixed by
>> https://github.com/ceph/ceph/pull/26712
>>
>>> pybind/mgr/diskprediction_cloud/module.py:12: error:
>>>   Module 'string' has no attribute 'maketrans'
>>
>>
>> which is already tracked as https://tracker.ceph.com/issues/38521
>>
>> By adding additional type annotations to our Python code, we could
>> enhance the quality of static type checking and thus reveal additional
>> bugs. This is of course not mandatory!
>>
>>
>> Here is the PR that adds a script that calls mypy:
>> https://github.com/ceph/ceph/pull/26715
>>
>> It also contains a list of messages printed by mypy.
> 

-- 
Ricardo Dias
Senior Software Engineer - Storage Team
SUSE Linux GmbH, GF: Felix Imendörffer, Jane Smithard, Graham Norton,
HRB 21284
(AG Nürnberg)

Attachment: signature.asc
Description: OpenPGP digital signature


[Index of Archives]     [CEPH Users]     [Ceph Large]     [Information on CEPH]     [Linux BTRFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux