Skip to content

Commit 4d8961e

Browse files
authored
Add some type hints to scenarios (#4276)
1 parent b558618 commit 4d8961e

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

src/molecule/command/matrix.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -79,4 +79,4 @@ def matrix(ctx, scenario_name, subcommand): # type: ignore[no-untyped-def] # pr
7979
command_args = {"subcommand": subcommand}
8080

8181
s = scenarios.Scenarios(base.get_configs(args, command_args), scenario_name)
82-
s.print_matrix() # type: ignore[no-untyped-call]
82+
s.print_matrix()

src/molecule/scenarios.py

+11-5
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,15 @@
2222

2323
import logging
2424

25+
from typing import TYPE_CHECKING
26+
2527
from molecule import util
2628

2729

30+
if TYPE_CHECKING:
31+
from molecule.scenario import Scenario
32+
33+
2834
LOG = logging.getLogger(__name__)
2935

3036

@@ -42,7 +48,7 @@ def __init__(self, configs, scenario_name=None) -> None: # type: ignore[no-unty
4248
self._scenario_name = scenario_name
4349
self._scenarios = self.all
4450

45-
def next(self): # type: ignore[no-untyped-def] # noqa: ANN201, D102
51+
def next(self) -> Scenario: # noqa: D102
4652
if not self._scenarios:
4753
raise StopIteration
4854
return self._scenarios.pop(0)
@@ -54,14 +60,14 @@ def __iter__(self): # type: ignore[no-untyped-def] # noqa: ANN204
5460
__next__ = next # Python 3.X compatibility
5561

5662
@property
57-
def all(self): # type: ignore[no-untyped-def] # noqa: ANN201
63+
def all(self) -> list[Scenario]:
5864
"""Return a list containing all scenario objects.
5965
6066
Returns:
6167
list
6268
"""
6369
if self._scenario_name:
64-
scenarios = self._filter_for_scenario() # type: ignore[no-untyped-call]
70+
scenarios = self._filter_for_scenario()
6571
self._verify() # type: ignore[no-untyped-call]
6672

6773
return scenarios
@@ -70,7 +76,7 @@ def all(self): # type: ignore[no-untyped-def] # noqa: ANN201
7076
scenarios.sort(key=lambda x: x.directory)
7177
return scenarios
7278

73-
def print_matrix(self): # type: ignore[no-untyped-def] # noqa: ANN201, D102
79+
def print_matrix(self) -> None: # noqa: D102
7480
msg = "Test matrix"
7581
LOG.info(msg)
7682

@@ -94,7 +100,7 @@ def _verify(self): # type: ignore[no-untyped-def] # noqa: ANN202
94100
msg = f"Scenario '{self._scenario_name}' not found. Exiting."
95101
util.sysexit_with_message(msg)
96102

97-
def _filter_for_scenario(self): # type: ignore[no-untyped-def] # noqa: ANN202
103+
def _filter_for_scenario(self) -> list[Scenario]:
98104
"""Find the scenario matching the provided scenario name and returns a list.
99105
100106
Returns:

0 commit comments

Comments
 (0)