Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dealing with the 79 character limit when writing python type annotations

In writing a script, I ended up with a function signature like the following

def do_multiprocess_action(some_argument: str, communication_pipe: typing.Optional[multiprocessing.connection.Connection]) -> subprocess.Popen:

In an attempt to comply with PEP8, I split the definition up like the below

def do_multiprocess_action(some_argument: str,
                           communication_pipe: typing.Optional[multiprocessing.connection.Connection]
                           ) -> subprocess.Popen:

but with the type anotation, the line is far too long. What's the idiomatic way to deal with this?

like image 565
ollien Avatar asked Aug 10 '26 20:08

ollien


1 Answers

You could define the annotation first, then write your function:

MultiprocessingConnection = typing.Optional[
    multiprocessing.connection.Connection]

def do_multiprocess_action(some_argument: str, 
    communication_pipe: MultiprocessingConnection) -> subprocess.Popen:
like image 193
Reblochon Masque Avatar answered Aug 13 '26 08:08

Reblochon Masque



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!