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.

Definitely, +1 agree, sounds great :)

[...]
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 ?

* 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



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