Skip to content

Commit 550f034

Browse files
committed
Fixup execute process
Mostly casts around get attribute
1 parent 2beeb74 commit 550f034

File tree

1 file changed

+19
-15
lines changed

1 file changed

+19
-15
lines changed

launch/launch/actions/execute_process.py

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
from typing import List
2121
from typing import Optional
2222
from typing import Text
23+
from typing import cast
2324

2425
from .execute_local import ExecuteLocal
2526

@@ -28,6 +29,8 @@
2829
from ..frontend import expose_action
2930
from ..frontend import Parser
3031
from ..some_substitutions_type import SomeSubstitutionsType
32+
33+
from ..substitution import Substitution
3134
from ..substitutions import TextSubstitution
3235

3336

@@ -250,7 +253,7 @@ def _parse_cmdline(
250253
:returns: a list of command line arguments.
251254
"""
252255
result_args = []
253-
arg = []
256+
arg: List[Substitution] = []
254257

255258
def _append_arg():
256259
nonlocal arg
@@ -315,35 +318,35 @@ def parse(
315318
ignore = []
316319

317320
if 'cmd' not in ignore:
318-
kwargs['cmd'] = cls._parse_cmdline(entity.get_attr('cmd'), parser)
321+
kwargs['cmd'] = cls._parse_cmdline(cast(str, entity.get_attr('cmd')), parser)
319322

320323
if 'cwd' not in ignore:
321-
cwd = entity.get_attr('cwd', optional=True)
324+
cwd = cast(Optional[str], entity.get_attr('cwd', optional=True))
322325
if cwd is not None:
323326
kwargs['cwd'] = parser.parse_substitution(cwd)
324327

325328
if 'name' not in ignore:
326-
name = entity.get_attr('name', optional=True)
329+
name = cast(Optional[str], entity.get_attr('name', optional=True))
327330
if name is not None:
328331
kwargs['name'] = parser.parse_substitution(name)
329332

330333
if 'prefix' not in ignore:
331-
prefix = entity.get_attr('launch-prefix', optional=True)
334+
prefix = cast(Optional[str], entity.get_attr('launch-prefix', optional=True))
332335
if prefix is not None:
333336
kwargs['prefix'] = parser.parse_substitution(prefix)
334337

335338
if 'output' not in ignore:
336-
output = entity.get_attr('output', optional=True)
339+
output = cast(Optional[str], entity.get_attr('output', optional=True))
337340
if output is not None:
338341
kwargs['output'] = parser.parse_substitution(output)
339342

340343
if 'respawn' not in ignore:
341-
respawn = entity.get_attr('respawn', optional=True)
344+
respawn = cast(Optional[str], entity.get_attr('respawn', optional=True))
342345
if respawn is not None:
343346
kwargs['respawn'] = parser.parse_substitution(respawn)
344347

345348
if 'respawn_delay' not in ignore:
346-
respawn_delay = entity.get_attr('respawn_delay', data_type=float, optional=True)
349+
respawn_delay = cast(Optional[float], entity.get_attr('respawn_delay', data_type=float, optional=True))
347350
if respawn_delay is not None:
348351
if respawn_delay < 0.0:
349352
raise ValueError(
@@ -353,7 +356,7 @@ def parse(
353356
kwargs['respawn_delay'] = respawn_delay
354357

355358
if 'sigkill_timeout' not in ignore:
356-
sigkill_timeout = entity.get_attr('sigkill_timeout', data_type=float, optional=True)
359+
sigkill_timeout = cast(Optional[float], entity.get_attr('sigkill_timeout', data_type=float, optional=True))
357360
if sigkill_timeout is not None:
358361
if sigkill_timeout < 0.0:
359362
raise ValueError(
@@ -363,7 +366,7 @@ def parse(
363366
kwargs['sigkill_timeout'] = str(sigkill_timeout)
364367

365368
if 'sigterm_timeout' not in ignore:
366-
sigterm_timeout = entity.get_attr('sigterm_timeout', data_type=float, optional=True)
369+
sigterm_timeout = cast(Optional[float], entity.get_attr('sigterm_timeout', data_type=float, optional=True))
367370
if sigterm_timeout is not None:
368371
if sigterm_timeout < 0.0:
369372
raise ValueError(
@@ -373,24 +376,25 @@ def parse(
373376
kwargs['sigterm_timeout'] = str(sigterm_timeout)
374377

375378
if 'shell' not in ignore:
376-
shell = entity.get_attr('shell', data_type=bool, optional=True)
379+
shell = cast(Optional[bool], entity.get_attr('shell', data_type=bool, optional=True))
377380
if shell is not None:
378381
kwargs['shell'] = shell
379382

380383
if 'emulate_tty' not in ignore:
381-
emulate_tty = entity.get_attr('emulate_tty', data_type=bool, optional=True)
384+
emulate_tty = cast(Optional[bool], entity.get_attr('emulate_tty', data_type=bool, optional=True))
382385
if emulate_tty is not None:
383386
kwargs['emulate_tty'] = emulate_tty
384387

385388
if 'additional_env' not in ignore:
386389
# Conditions won't be allowed in the `env` tag.
387390
# If that feature is needed, `set_enviroment_variable` and
388391
# `unset_enviroment_variable` actions should be used.
389-
env = entity.get_attr('env', data_type=List[Entity], optional=True)
392+
# TODO: Fixup the data_type annotation
393+
env = cast(Optional[List[Entity]], entity.get_attr('env', data_type=List[Entity], optional=True)) # type: ignore
390394
if env is not None:
391395
kwargs['additional_env'] = {
392-
tuple(parser.parse_substitution(e.get_attr('name'))):
393-
parser.parse_substitution(e.get_attr('value')) for e in env
396+
tuple(parser.parse_substitution(cast(str, e.get_attr('name')))):
397+
parser.parse_substitution(cast(str, e.get_attr('value'))) for e in env
394398
}
395399
for e in env:
396400
e.assert_entity_completely_parsed()

0 commit comments

Comments
 (0)