summaryrefslogtreecommitdiff
path: root/coverage
diff options
context:
space:
mode:
Diffstat (limited to 'coverage')
-rw-r--r--coverage/control.py10
-rw-r--r--coverage/sqldata.py4
-rw-r--r--coverage/types.py13
3 files changed, 21 insertions, 6 deletions
diff --git a/coverage/control.py b/coverage/control.py
index cdea42ee..e385f0e2 100644
--- a/coverage/control.py
+++ b/coverage/control.py
@@ -47,7 +47,7 @@ from coverage.report import render_report
from coverage.results import Analysis
from coverage.summary import SummaryReporter
from coverage.types import (
- TConfigurable, TConfigSectionIn, TConfigValueIn, TConfigValueOut,
+ FilePath, TConfigurable, TConfigSectionIn, TConfigValueIn, TConfigValueOut,
TFileDisposition, TLineNo, TMorf,
)
from coverage.xmlreport import XmlReporter
@@ -113,13 +113,13 @@ class Coverage(TConfigurable):
def __init__( # pylint: disable=too-many-arguments
self,
- data_file: Optional[Union[str, DefaultValue]] = DEFAULT_DATAFILE,
+ data_file: Optional[Union[FilePath, DefaultValue]] = DEFAULT_DATAFILE,
data_suffix: Optional[Union[str, bool]] = None,
cover_pylib: Optional[bool] = None,
auto_data: bool = False,
timid: Optional[bool] = None,
branch: Optional[bool] = None,
- config_file: Union[str, bool] = True,
+ config_file: Union[FilePath, bool] = True,
source: Optional[Iterable[str]] = None,
source_pkgs: Optional[Iterable[str]] = None,
omit: Optional[Union[str, Iterable[str]]] = None,
@@ -227,6 +227,8 @@ class Coverage(TConfigurable):
self._no_disk = data_file is None
if isinstance(data_file, DefaultValue):
data_file = None
+ if data_file is not None:
+ data_file = os.fspath(data_file)
# This is injectable by tests.
self._debug_file: Optional[IO[str]] = None
@@ -267,6 +269,8 @@ class Coverage(TConfigurable):
self._should_write_debug = True
# Build our configuration from a number of sources.
+ if not isinstance(config_file, bool):
+ config_file = os.fspath(config_file)
self.config = read_coverage_config(
config_file=config_file,
warn=self._warn,
diff --git a/coverage/sqldata.py b/coverage/sqldata.py
index bb26e4d5..15b30ae9 100644
--- a/coverage/sqldata.py
+++ b/coverage/sqldata.py
@@ -31,7 +31,7 @@ from coverage.exceptions import CoverageException, DataError
from coverage.files import PathAliases
from coverage.misc import file_be_gone, isolate_module
from coverage.numbits import numbits_to_nums, numbits_union, nums_to_numbits
-from coverage.types import TArc, TDebugCtl, TLineNo, TWarnFn
+from coverage.types import FilePath, TArc, TDebugCtl, TLineNo, TWarnFn
from coverage.version import __version__
os = isolate_module(os)
@@ -216,7 +216,7 @@ class CoverageData(AutoReprMixin):
def __init__(
self,
- basename: Optional[str] = None,
+ basename: Optional[FilePath] = None,
suffix: Optional[Union[str, bool]] = None,
no_disk: bool = False,
warn: Optional[TWarnFn] = None,
diff --git a/coverage/types.py b/coverage/types.py
index b8135d05..e01f451e 100644
--- a/coverage/types.py
+++ b/coverage/types.py
@@ -7,9 +7,12 @@ Types for use throughout coverage.py.
from __future__ import annotations
+import os
+import pathlib
+
from types import FrameType, ModuleType
from typing import (
- Any, Callable, Dict, Iterable, List, Mapping, Optional, Set, Tuple, Union,
+ Any, Callable, Dict, Iterable, List, Mapping, Optional, Set, Tuple, Type, Union,
TYPE_CHECKING,
)
@@ -23,6 +26,14 @@ else:
class Protocol: # pylint: disable=missing-class-docstring
pass
+## File paths
+
+# For arguments that are file paths:
+FilePath = Union[str, os.PathLike]
+# For testing FilePath arguments
+FilePathClasses = [str, pathlib.Path]
+FilePathType = Union[Type[str], Type[pathlib.Path]]
+
## Python tracing
class TTraceFn(Protocol):