Re: [BuildStream] Proposal: Consider adding type hints



On Tue, 2019-06-25 at 21:39 +0100, Chandan Singh wrote:

Hi all,
I wanted to start the conversation about adding type hints (as specified by PEP
484 [1]) to some parts of the BuildStream code.


My +1 definitely!


‐‐‐‐‐‐‐ Original Message ‐‐‐‐‐‐‐
On Wednesday, 26 June 2019 10:48, Tristan Van Berkom via buildstream-list <buildstream-list gnome org> wrote:


For the public API, we already attempt to add types. However, it is
not covered by
any automated type analyzer given how it is done as part of the docstring.
Switching to type hints would allow one to run static type checkers like
mypy [2], pytype [3] pyright [4] etc. Neither of them is quite perfect just yet
but they are getting better with time.

I suppose these checkers can only have some measure of success in
catching errors, and only when the calling code exists in the codebase
being checked.

I'm curious if we can take this one step further:

-   Can we automatically introduce runtime assertions on function
    arguments throughout the codebase ?

The answer is yes! https://github.com/Stewori/pytypes does this quite well and can be enabled/disabled at 
import time!

That would mean slightly slower imports but we would be able to typecheck only at test time/on demand.


-   Can we distinguish between public API surface and internal functions,
    such that we can perhaps keep the runtime assertions active only
    on the public API surface, when asserts are disabled with `-O` ?

    Obviously, having runtime assertions at every function entry point
    would be expensive, but worthwhile in development, but surely a thin
    layer of type checking on public API entry points is worth the small
    expense (also worth benchmarking).

    Cheers,
    -Tristan

Having the pytypes checks at runtime would be usable/disableable if we want. I'm happy to help for getting 
this up and running

Cheers,
Ben



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