Skip to content

Improve types of context.run #947

Closed
Closed

Description

@kasium

According to the types, output = context.run("echo") returns possibly None, which makes sense for asynchronous tasks. For this example, the types are wrong, since never None could be returned. Can you please add an overload improving it?

Activity

  1. MartinBernstorff commented on Jun 27, 2023

    @MartinBernstorff

    I'd strongly support this suggestion!

    Based on my testing, this was added in Invoke 2.1.2.

    E.g. the type of this statement differs between:

    result = c.run(f"ruff check . {'--fix' if auto_fix else ''}", warn=True)

    The type of this is:

    2.1.1: Result
    2.1.2: Result | None
    

    The current type hints suggests that we should always guard against None as a return type, making the code much more verbose. I don't know enough about async to know to which extent this is avoidable, but adding guards every time we get a return object is very costly to readability and maintainability. Would love to know your take on this, @bitprophet.

  2. kuwv commented on Jul 10, 2023

    @kuwv
    Contributor
  3. bitprophet commented on Jun 16, 2025

    @bitprophet
    Member

    I am prototyping some fixes for this, in tandem with #779 it feels like returning None some of the time (when disown=True) was a pre-type-hints bad idea - so I'm going to try just changing the behavior to return a Result even in that case, making the correct return value type hint simply Result.

  4. added a commit that references this issue on Jun 17, 2025
    6417e20
  5. added 8 commits that reference this issue on Oct 13, 2025
    92aa3f2
    d4aafff
    9b3d790
    2808275
    e899b05
    0b1e39d
    96a2c80
    cd32e38
  6. added 2 commits that reference this issue on Apr 5, 2026
    12ab5d6
    7aa7deb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions