Skip to content

Commit 466dbb9

Browse files
committed
Use a dict for scope indices
1 parent 0579187 commit 466dbb9

File tree

1 file changed

+3
-8
lines changed

1 file changed

+3
-8
lines changed

src/_pytest/scope.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
Also this makes the module light to import, as it should.
99
"""
1010
from enum import Enum
11-
from functools import lru_cache
1211
from typing import Optional
1312
from typing import TYPE_CHECKING
1413

@@ -29,7 +28,7 @@ class Scope(Enum):
2928

3029
def index(self) -> int:
3130
"""Return this scope index. Smaller numbers indicate higher scopes (Session = 0)."""
32-
return _scope_to_index(self)
31+
return _SCOPE_INDICES[self]
3332

3433
def next(self) -> "Scope":
3534
"""Return the next scope (from top to bottom)."""
@@ -70,9 +69,5 @@ def from_user(
7069
Scope.Class: Scope.Function,
7170
}
7271

73-
74-
@lru_cache(maxsize=None)
75-
def _scope_to_index(scope: Scope) -> int:
76-
"""Implementation of Scope.index() as a free function so we can cache it."""
77-
scopes = list(Scope)
78-
return scopes.index(scope)
72+
# Maps a scope to its internal index, with Session = 0, Package = 1, and so on.
73+
_SCOPE_INDICES = {s: i for i, s in enumerate(Scope)}

0 commit comments

Comments
 (0)