Skip to content

Commit ad02f6f

Browse files
authored
Merge pull request #6525 from blueyed/typing-session
typing: Session.__init__
2 parents 85df6bb + bd6ba3f commit ad02f6f

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

src/_pytest/main.py

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,30 @@
66
import os
77
import sys
88
from typing import Dict
9+
from typing import FrozenSet
10+
from typing import List
911

1012
import attr
1113
import py
1214

1315
import _pytest._code
1416
from _pytest import nodes
17+
from _pytest.compat import TYPE_CHECKING
18+
from _pytest.config import Config
1519
from _pytest.config import directory_arg
1620
from _pytest.config import hookimpl
1721
from _pytest.config import UsageError
1822
from _pytest.fixtures import FixtureManager
23+
from _pytest.nodes import Node
1924
from _pytest.outcomes import exit
2025
from _pytest.runner import collect_one_node
2126
from _pytest.runner import SetupState
2227

2328

29+
if TYPE_CHECKING:
30+
from _pytest.python import Package
31+
32+
2433
class ExitCode(enum.IntEnum):
2534
"""
2635
.. versionadded:: 5.0
@@ -383,7 +392,7 @@ class Session(nodes.FSCollector):
383392
# Set on the session by fixtures.pytest_sessionstart.
384393
_fixturemanager = None # type: FixtureManager
385394

386-
def __init__(self, config):
395+
def __init__(self, config: Config) -> None:
387396
nodes.FSCollector.__init__(
388397
self, config.rootdir, parent=None, config=config, session=self, nodeid=""
389398
)
@@ -394,14 +403,16 @@ def __init__(self, config):
394403
self.trace = config.trace.root.get("collection")
395404
self._norecursepatterns = config.getini("norecursedirs")
396405
self.startdir = config.invocation_dir
397-
self._initialpaths = frozenset()
406+
self._initialpaths = frozenset() # type: FrozenSet[py.path.local]
407+
398408
# Keep track of any collected nodes in here, so we don't duplicate fixtures
399-
self._node_cache = {}
409+
self._node_cache = {} # type: Dict[str, List[Node]]
410+
# Dirnames of pkgs with dunder-init files.
411+
self._pkg_roots = {} # type: Dict[py.path.local, Package]
412+
400413
self._bestrelpathcache = _bestrelpath_cache(
401414
config.rootdir
402415
) # type: Dict[str, str]
403-
# Dirnames of pkgs with dunder-init files.
404-
self._pkg_roots = {}
405416

406417
self.config.pluginmanager.register(self, name="session")
407418

0 commit comments

Comments
 (0)