top | item 45601663

(no title)

dmadisetti | 4 months ago

Arguments are typed if explicitly specified in definition, e.g.

    ```python
    @app.cell
    def my_cell():
        x : int = 1
        return (x,)

    @app.cell
    def consumer(x : int):
        y = x
        return
    ```
We've talked about building out implicit typing into our serialization- but that may be a larger can of worms.

discuss

order

sixo|4 months ago

That would be wonderful. A lot of the arguments are just imports, and these would have probably have the largest upside. It would be great if there was a construct like

    import numpy

    @app.cell
    def my_cell(np: types.ModuleType[numpy]):
        ... editor treats np like `import numpy as np` ...

I do not use Python enough to know if something like this can be hacked together. But if not, I imagine could be PIPed into the standard library if a convincing case were made for it.

dmadisetti|4 months ago

We've addressed this too by allowing a setup cell:

    ...

    with app.setup:
        import numpy as np
    
    @app.cell
    def cell_uses_np():
        # no np needed in signature
        result = np....
The best part about this pattern is that it enables "pure" (only dependent on setup cell) functions to be addressable:

    with app.setup:
        from typing import Optional, Any

    @app.function
    def my_fn(arg: Optional[Any]) -> Any:
        ...
but nice convergent design :) glad to see to see we're addressing pain points