[SciPy-Dev] Static Typing

Serge Guelton serge.guelton at telecom-bretagne.eu
Wed Jun 30 16:30:17 EDT 2021


On Wed, Jun 30, 2021 at 08:14:55PM +0200, Ralf Gommers wrote:
> 
> 
> On Wed, Jun 30, 2021 at 8:07 PM Stefan van der Walt <[1]stefanv at berkeley.edu>
> wrote:
> 
>     On Wed, Jun 30, 2021, at 09:03, Evgeni Burovski wrote:
>     > ISTM it's important that annotations are optional in the sense that we
>     > do not explicitly require that new code is typed. If someone is
>     > willing to add them, great (and if someone is willing to review a
>     > typing PR, even better :-)). But this should be possible to do in a
>     > follow-up PR, not as a requirement for an enhancement PR.
> 
>     I agree, especially given that the typing notation is still changing.  For
>     example, they're currently working out a shorthand for typing function
>     definitions (and I'm sure other simplifications are in the pipeline too).

I think it's worth noting that some numpy interface are inherently incompatible
with fine-grain static typing. On simple example would be

def foo(x : ndarray[int, :, :], strict: bool):
    return np.mean(x, keepdims=strict)

What should be the return type of `foo`? We can't tell precisely, because it
depends on the runtime value of strict. We're left with something alonside "this
returns an array of the same dimension or a scalar of the same dtype"

I don't know how much this dynamicity leaks to scipy interface, but it does look
like a difficult problem to solve.


More information about the SciPy-Dev mailing list