Skip to content

Commit 0fbfd1c

Browse files
authored
Merge pull request #9152 from bluetech/mark-optimize
mark/structures: slightly optimize some functions
2 parents 2cfce8d + 637e8ef commit 0fbfd1c

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

src/_pytest/mark/structures.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -360,30 +360,29 @@ def __call__(self, *args: object, **kwargs: object):
360360
return self.with_args(*args, **kwargs)
361361

362362

363-
def get_unpacked_marks(obj) -> List[Mark]:
363+
def get_unpacked_marks(obj: object) -> Iterable[Mark]:
364364
"""Obtain the unpacked marks that are stored on an object."""
365365
mark_list = getattr(obj, "pytestmark", [])
366366
if not isinstance(mark_list, list):
367367
mark_list = [mark_list]
368368
return normalize_mark_list(mark_list)
369369

370370

371-
def normalize_mark_list(mark_list: Iterable[Union[Mark, MarkDecorator]]) -> List[Mark]:
371+
def normalize_mark_list(
372+
mark_list: Iterable[Union[Mark, MarkDecorator]]
373+
) -> Iterable[Mark]:
372374
"""
373375
Normalize an iterable of Mark or MarkDecorator objects into a list of marks
374376
by retrieving the `mark` attribute on MarkDecorator instances.
375377
376378
:param mark_list: marks to normalize
377379
:returns: A new list of the extracted Mark objects
378380
"""
379-
380-
def parse_mark(mark: Union[Mark, MarkDecorator]) -> Mark:
381+
for mark in mark_list:
381382
mark_obj = getattr(mark, "mark", mark)
382383
if not isinstance(mark_obj, Mark):
383384
raise TypeError(f"got {repr(mark_obj)} instead of Mark")
384-
return mark_obj
385-
386-
return [parse_mark(x) for x in mark_list]
385+
yield mark_obj
387386

388387

389388
def store_mark(obj, mark: Mark) -> None:
@@ -394,7 +393,7 @@ def store_mark(obj, mark: Mark) -> None:
394393
assert isinstance(mark, Mark), mark
395394
# Always reassign name to avoid updating pytestmark in a reference that
396395
# was only borrowed.
397-
obj.pytestmark = get_unpacked_marks(obj) + [mark]
396+
obj.pytestmark = [*get_unpacked_marks(obj), mark]
398397

399398

400399
# Typing for builtin pytest marks. This is cheating; it gives builtin marks

0 commit comments

Comments
 (0)