On 08/10/2017 03:26 AM, Fraser Tweedale via FreeIPA-devel wrote:
> On Wed, Aug 09, 2017 at 10:18:33AM +0200, Christian Heimes via FreeIPA-devel 
> wrote:
>> On 2017-08-08 08:04, Fraser Tweedale via FreeIPA-devel wrote:
>>> Hi team,
>>> At PyCon Australia on the weekend I was reminded of PEP-484 type
>>> hinting** and the Mypy type checker for Python.
>>> With focus of FreeIPA project shifting more towards stability,
>>> quality and maintainability, and with Python 3 porting work nearly
>>> wrapped up, now is the time to think about how we can get more
>>> confidence in our code not just from tests, but from the code
>>> itself.  Static checking of annotated types can help us there, and
>>> Mypy can let us begin to do this when writing new code or
>>> refactoring old code.  Furthermore there is a benefit for IDE-users
>>> where plugins can use type annotations to provide better completion
>>> suggestions, etc.  For an overview of Mypy please see the PyCon AU
>>> talk[1] or the docs[2].
>>> [1] https://www.youtube.com/watch?v=mXfsMDM3LwQ
>>> [2] http://mypy.readthedocs.io/en/latest/index.html
>>> So, what's the plan?  Alongside my other tasks, I'm going to start
>>> looking at how we could use Mypy in FreeIPA CI, and see what it is
>>> like using types in some of the areas I'm familiar with e.g.
>>> ipalib.x509.  Based on my findings I'll update the team on the wins
>>> and challenges and we can decide how to proceed from there.
>> Felipe ask me about typing and Mypy a couple of weeks ago. It's a good
>> idea and we should do it. But I advise against typing information in the
>> source code. FreeIPA should use external stub files for two reasons.
>> First of all it is required to stay compatible with Python 2. And more
>> importantly it's faster. FreeIPA's CLI scripts already take several
>> hundred milliseconds to execute. Typing would slow them down even further.
> I disagree with using stub files.  Types should be declared where
> the functions are defined.  Types are documentation and proximity is
> important (for humans).
> Fortunately, Mypy supports "type comments" in addition to PEP 3107
> function annotations.  Mypy groks them but CPython will treat them
> as comments and discard.  This allows us to use type hints with no
> runtime cost for the CLI scripts.
I like the idea of specifying types and it can also be helpful when
reading the code, because it serves as additional documentation. For
this reason, I also think it's important not to use stub files.

The Python 3.6 syntax looks awesome and I'd like to use it. However,
since we have to support Python 2, we'd have to use the comments. I
don't really like that, because it's not a part of the in-line code.
There's also a big downside -- you can't use partial annotations with

Tomas Krizek

PGP: 4A8B A48C 2AED 933B D495  C509 A1FB A5F7 EF8C 4869

Attachment: signature.asc
Description: OpenPGP digital signature

FreeIPA-devel mailing list -- freeipa-devel@lists.fedorahosted.org
To unsubscribe send an email to freeipa-devel-le...@lists.fedorahosted.org

Reply via email to