pyinvoke / invoke

Pythonic task management & command execution.
http://pyinvoke.org
BSD 2-Clause "Simplified" License
4.31k stars 365 forks source link

Improve types of context.run #947

Open kasium opened 1 year ago

kasium commented 1 year ago

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?

MartinBernstorff commented 1 year ago

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.

kuwv commented 12 months ago

956