Python static type checking

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

 



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.





-- 
SUSE Linux GmbH, GF: Felix Imendörffer, Jane Smithard, Graham Norton,
HRB 21284 (AG Nürnberg)




[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