Skip to content

Commit fa46479

Browse files
committed
Fix pyright issues
1 parent 20a37ca commit fa46479

15 files changed

Lines changed: 57 additions & 42 deletions

File tree

dfetch/manifest/manifest.py

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@
2727
import yaml
2828
from typing_extensions import TypedDict
2929

30-
import dfetch.manifest.validate
3130
from dfetch import DEFAULT_MANIFEST_NAME
3231
from dfetch.log import get_logger
3332
from dfetch.manifest.project import ProjectEntry, ProjectEntryDict
3433
from dfetch.manifest.remote import Remote, RemoteDict
34+
from dfetch.manifest.validate import validate
3535
from dfetch.util.util import find_file, prefix_runtime_exceptions
3636

3737
logger = get_logger(__name__)
@@ -89,7 +89,7 @@ class ManifestDict( # pylint: disable=too-many-ancestors
8989
): # When https://www.python.org/dev/peps/pep-0655/ is accepted, only make remotes optional
9090
"""Serialized dict types."""
9191

92-
version: str
92+
version: Union[int, str]
9393
remotes: Sequence[Union[RemoteDict, Remote]]
9494
projects: Sequence[Union[ProjectEntryDict, ProjectEntry, Dict[str, str]]]
9595

@@ -104,7 +104,7 @@ class Manifest:
104104

105105
def __init__(self, manifest: ManifestDict) -> None:
106106
"""Create the manifest."""
107-
self.__version: str = manifest.get("version", self.CURRENT_VERSION)
107+
self.__version: str = str(manifest.get("version", self.CURRENT_VERSION))
108108

109109
self._remotes, default_remotes = self._determine_remotes(
110110
manifest.get("remotes", [])
@@ -114,6 +114,9 @@ def __init__(self, manifest: ManifestDict) -> None:
114114
default_remotes = list(self._remotes.values())[0:1]
115115

116116
self._default_remote = None if not default_remotes else default_remotes[0]
117+
118+
if "projects" not in manifest:
119+
raise KeyError("No projects in manifest!")
117120
self._projects = self._init_projects(manifest["projects"])
118121

119122
def _init_projects(
@@ -133,6 +136,8 @@ def _init_projects(
133136
_projects: Dict[str, ProjectEntry] = {}
134137
for project in projects:
135138
if isinstance(project, dict):
139+
if "name" not in project:
140+
raise KeyError("Missing name!")
136141
last_project = _projects[project["name"]] = ProjectEntry.from_yaml(
137142
project, self._default_remote
138143
)
@@ -306,11 +311,11 @@ def get_manifest() -> Tuple[Manifest, str]:
306311
"""Get manifest and its path."""
307312
logger.debug("Looking for manifest")
308313
manifest_path = find_manifest()
309-
dfetch.manifest.validate.validate(manifest_path)
314+
validate(manifest_path)
310315

311316
logger.debug(f"Using manifest {manifest_path}")
312317
return (
313-
dfetch.manifest.manifest.Manifest.from_file(manifest_path),
318+
Manifest.from_file(manifest_path),
314319
manifest_path,
315320
)
316321

@@ -320,16 +325,16 @@ def get_childmanifests(skip: Optional[List[str]] = None) -> List[Tuple[Manifest,
320325
skip = skip or []
321326
logger.debug("Looking for sub-manifests")
322327

323-
childmanifests = []
328+
childmanifests: List[Tuple[Manifest, str]] = []
324329
for path in find_file(DEFAULT_MANIFEST_NAME, "."):
325330
path = os.path.realpath(path)
326331
if path not in skip:
327332
logger.debug(f"Found sub-manifests {path}")
328333
with prefix_runtime_exceptions(
329334
pathlib.Path(path).relative_to(os.path.dirname(os.getcwd())).as_posix()
330335
):
331-
dfetch.manifest.validate.validate(path)
332-
childmanifest = dfetch.manifest.manifest.Manifest.from_file(path)
336+
validate(path)
337+
childmanifest = Manifest.from_file(path)
333338
childmanifests += [(childmanifest, path)]
334339

335340
return childmanifests

dfetch/manifest/project.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,8 @@ class ProjectEntry: # pylint: disable=too-many-instance-attributes
281281

282282
def __init__(self, kwargs: ProjectEntryDict) -> None:
283283
"""Create the project entry."""
284+
if "name" not in kwargs:
285+
raise RuntimeError("Name missing from Project!")
284286
self._name: str = kwargs["name"]
285287
self._revision: str = kwargs.get("revision", "")
286288

dfetch/project/metadata.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import yaml
77
from typing_extensions import TypedDict
88

9-
import dfetch.manifest.manifest
9+
from dfetch.manifest.project import ProjectEntry
1010
from dfetch.manifest.version import Version
1111

1212
DONT_EDIT_WARNING = """\
@@ -52,9 +52,7 @@ def __init__(self, kwargs: Options) -> None:
5252
self._patch: str = str(kwargs.get("patch", ""))
5353

5454
@classmethod
55-
def from_project_entry(
56-
cls, project: dfetch.manifest.project.ProjectEntry
57-
) -> "Metadata":
55+
def from_project_entry(cls, project: ProjectEntry) -> "Metadata":
5856
"""Create a metadata object from a project entry."""
5957
data: Options = {
6058
"branch": project.branch,

dfetch/project/vcs.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
from halo import Halo
1010
from patch_ng import fromfile
1111

12-
import dfetch.manifest.manifest
1312
from dfetch.log import get_logger
13+
from dfetch.manifest.project import ProjectEntry
1414
from dfetch.manifest.version import Version
1515
from dfetch.project.abstract_check_reporter import AbstractCheckReporter
1616
from dfetch.project.metadata import Metadata
@@ -31,7 +31,7 @@ class VCS(ABC):
3131
DEFAULT_BRANCH = ""
3232
LICENSE_GLOBS = ["licen[cs]e*", "copying*", "copyright*"]
3333

34-
def __init__(self, project: dfetch.manifest.project.ProjectEntry) -> None:
34+
def __init__(self, project: ProjectEntry) -> None:
3535
"""Create the VCS."""
3636
self.__project = project
3737
self.__metadata = Metadata.from_project_entry(self.__project)
@@ -355,7 +355,7 @@ def current_revision(self) -> str:
355355
"""Get the revision of the metadata file."""
356356

357357
@abstractmethod
358-
def get_diff(self, old_revision: str, new_revision: Optional[str]) -> str:
358+
def get_diff(self, old_revision: str, new_revision: Optional[str]) -> str: # noqa
359359
"""Get the diff of two revisions."""
360360

361361
@staticmethod

dfetch/reporting/check/sarif_reporter.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,10 @@
7070
7171
"""
7272

73+
# Underlying sarif-tools is generated with attr which pyright does not support
74+
# See https://github.com/microsoft/pyright/issues/146
75+
# pyright: reportCallIssue=false
76+
7377
import json
7478
import os
7579
from enum import Enum
@@ -154,7 +158,7 @@ def __init__(self, manifest_path: str, report_path: str) -> None:
154158
)
155159
]
156160
self._run.results = []
157-
self._run.newline_sequences = None
161+
self._run.newline_sequences = []
158162

159163
@staticmethod
160164
def _severity_to_level(severity: IssueSeverity) -> SarifResultLevel:

dfetch/reporting/sbom_reporter.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ def _split_url(url: str) -> List[str]:
108108

109109
def dump_to_file(self, outfile: str) -> bool:
110110
"""Dump the SBoM to file."""
111-
output_format = (
111+
output_format = OutputFormat(
112112
OutputFormat.XML if outfile.endswith(".xml") else OutputFormat.JSON
113113
)
114114
outputter = cast(Json, get_instance(bom=self._bom, output_format=output_format))

doc/_ext/scenario_directive.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
import os
2525
import re
26-
from typing import Iterable
26+
from typing import Tuple
2727

2828
from docutils import nodes
2929
from docutils.parsers.rst import Directive
@@ -39,20 +39,20 @@ class ScenarioIncludeDirective(Directive):
3939
"scenario": str,
4040
}
4141

42-
def list_of_scenarios(self, feature_file_path: str) -> Iterable[str]:
42+
def list_of_scenarios(self, feature_file_path: str) -> Tuple[str]:
4343
"""Parse the list of scenarios from the feature file"""
4444
env = self.state.document.settings.env
4545
feature_path = os.path.abspath(os.path.join(env.app.srcdir, feature_file_path))
4646
if not os.path.exists(feature_path):
4747
raise self.error(f"Feature file not found: {feature_path}")
4848

4949
with open(feature_path, encoding="utf-8") as f:
50-
scenarios = [
50+
scenarios = tuple(
5151
m[1]
5252
for m in re.findall(
5353
r"^\s*(Scenario(?: Outline)?):\s*(.+)$", f.read(), re.MULTILINE
5454
)
55-
]
55+
)
5656
return scenarios
5757

5858
def run(self):

features/steps/generic_steps.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""Steps for features tests."""
22

3+
# pyright: reportRedeclaration=false, reportAttributeAccessIssue=false
34
# pylint: disable=function-redefined, missing-function-docstring
45

56
import difflib

features/steps/git_steps.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""Steps for features tests."""
22

33
# pylint: disable=function-redefined, missing-function-docstring, import-error
4+
# pyright: reportRedeclaration=false, reportAttributeAccessIssue=false
45

56
import os
67
import pathlib

features/steps/manifest_steps.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""Steps for features tests."""
22

33
# pylint: disable=function-redefined, missing-function-docstring, import-error
4-
4+
# pyright: reportRedeclaration=false, reportAttributeAccessIssue=false
55

66
import os
77
import pathlib

0 commit comments

Comments
 (0)