From c3a3421721788d863012330bc0789b828ce4bcd0 Mon Sep 17 00:00:00 2001 From: Ned Batchelder Date: Fri, 24 Feb 2023 07:34:19 -0500 Subject: [PATCH] fix: export our public names for type checking. #1564 --- CHANGES.rst | 4 ++++ coverage/__init__.py | 28 +++++++++++++++++++++------- coverage/cmdline.py | 2 ++ coverage/html.py | 3 ++- coverage/xmlreport.py | 3 ++- 5 files changed, 31 insertions(+), 9 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index b493f68e7..b7e8fd27b 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -23,6 +23,10 @@ Unreleased - Fix: the PyPI page had broken links to documentation pages, but no longer does, closing `issue 1566`_. +- Fix: public members of the coverage module are now properly indicated so that + mypy will find them, fixing `issue 1564`_. + +.. _issue 1564: https://github.com/nedbat/coveragepy/issues/1564 .. _issue 1566: https://github.com/nedbat/coveragepy/issues/1566 diff --git a/coverage/__init__.py b/coverage/__init__.py index efd0a6f03..054e37dff 100644 --- a/coverage/__init__.py +++ b/coverage/__init__.py @@ -9,15 +9,29 @@ """ -import sys +# mypy's convention is that "import as" names are public from the module. +# We import names as themselves to indicate that. Pylint sees it as pointless, +# so disable its warning. +# pylint: disable=useless-import-alias -from coverage.version import __version__, __url__, version_info +import sys -from coverage.control import Coverage, process_startup -from coverage.data import CoverageData -from coverage.exceptions import CoverageException -from coverage.plugin import CoveragePlugin, FileTracer, FileReporter -from coverage.pytracer import PyTracer +from coverage.version import ( + __version__ as __version__, + version_info as version_info, +) + +from coverage.control import ( + Coverage as Coverage, + process_startup as process_startup, +) +from coverage.data import CoverageData as CoverageData +from coverage.exceptions import CoverageException as CoverageException +from coverage.plugin import ( + CoveragePlugin as CoveragePlugin, + FileReporter as FileReporter, + FileTracer as FileTracer, +) # Backward compatibility. coverage = Coverage diff --git a/coverage/cmdline.py b/coverage/cmdline.py index 338d8a25a..ef760a503 100644 --- a/coverage/cmdline.py +++ b/coverage/cmdline.py @@ -27,6 +27,7 @@ from coverage.exceptions import _BaseCoverageException, _ExceptionDuringRun, NoSource from coverage.execfile import PyRunner from coverage.results import Numbers, should_fail_under +from coverage.version import __url__ # When adding to this file, alphabetization is important. Look for # "alphabetize" comments throughout. @@ -574,6 +575,7 @@ def show_help( program_name = program_name[:-len(auto_suffix)] help_params = dict(coverage.__dict__) + help_params["__url__"] = __url__ help_params['program_name'] = program_name if HAS_CTRACER: help_params['extension_modifier'] = 'with C extension' diff --git a/coverage/html.py b/coverage/html.py index 9e1b11b20..ae09bc37d 100644 --- a/coverage/html.py +++ b/coverage/html.py @@ -24,6 +24,7 @@ from coverage.results import Analysis, Numbers from coverage.templite import Templite from coverage.types import TLineNo, TMorf +from coverage.version import __url__ if TYPE_CHECKING: @@ -238,7 +239,7 @@ def __init__(self, cov: Coverage) -> None: 'len': len, # Constants for this report. - '__url__': coverage.__url__, + '__url__': __url__, '__version__': coverage.__version__, 'title': title, 'time_stamp': format_local_datetime(datetime.datetime.now()), diff --git a/coverage/xmlreport.py b/coverage/xmlreport.py index 6867f2e92..65da11d23 100644 --- a/coverage/xmlreport.py +++ b/coverage/xmlreport.py @@ -14,12 +14,13 @@ from dataclasses import dataclass from typing import Any, Dict, IO, Iterable, Optional, TYPE_CHECKING, cast -from coverage import __url__, __version__, files +from coverage import __version__, files from coverage.misc import isolate_module, human_sorted, human_sorted_items from coverage.plugin import FileReporter from coverage.report import get_analysis_to_report from coverage.results import Analysis from coverage.types import TMorf +from coverage.version import __url__ if TYPE_CHECKING: from coverage import Coverage