Skip to content

Commit 382c2da

Browse files
Fix type errors
1 parent 12d9935 commit 382c2da

File tree

3 files changed

+16
-7
lines changed

3 files changed

+16
-7
lines changed

client/configuration/exceptions.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,8 @@ def __init__(self, message: str) -> None:
1818
class InvalidPythonVersion(InvalidConfiguration):
1919
def __init__(self, message: str) -> None:
2020
super().__init__(message)
21+
22+
23+
class InvalidPackage(ValueError):
24+
def __init__(self, pkg_name: str) -> None:
25+
super().__init__(f"Invalid package: {pkg_name} does not exist.")

client/configuration/search_path.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@
2828
LOG: logging.Logger = logging.getLogger(__name__)
2929

3030
dist_info_in_root: Dict[str, List[str]] = {}
31-
_site_filter = re.compile(r".*-([0-99]\.)*dist-info")
31+
_site_filter: re.Pattern[str] = re.compile(r".*-([0-99]\.)*dist-info")
3232

33-
_PYCACHE = re.compile("__pycache__")
33+
_PYCACHE: re.Pattern[str] = re.compile("__pycache__")
3434

3535

3636
def _expand_relative_root(path: str, relative_root: str) -> str:
@@ -78,7 +78,7 @@ class SitePackageElement(Element):
7878
package_name: str
7979
is_toplevel_module: bool = False
8080

81-
def package_path(self) -> Union[str, None]:
81+
def package_path(self) -> str:
8282
if not self.is_toplevel_module:
8383
return self.package_name
8484

@@ -97,10 +97,14 @@ def package_path(self) -> Union[str, None]:
9797
dist_info_path = f"{self.site_root}/{directory}"
9898
break
9999
else:
100-
return None
100+
raise exceptions.InvalidPackage(self.package_name)
101101

102-
not_toplevel_patterns: Tuple[re.Pattern] = (this_pkg_filter, _PYCACHE)
102+
not_toplevel_patterns: Tuple[re.Pattern[str], re.Pattern[str]] = (
103+
this_pkg_filter,
104+
_PYCACHE,
105+
)
103106

107+
# pyre-fixme[61]: Local variable `dist_info_path` is undefined, or not always defined.
104108
with open(file=f"{dist_info_path}/RECORD", mode="r") as record:
105109
files = []
106110
for val in [line.split(",") for line in record.readlines()]:
@@ -114,7 +118,7 @@ def package_path(self) -> Union[str, None]:
114118
else:
115119
return file
116120

117-
return None
121+
raise exceptions.InvalidPackage(self.package_name)
118122

119123
def path(self) -> str:
120124
return os.path.join(self.site_root, self.package_path())

client/configuration/tests/search_path_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ def test_process_required_raw_elements_site_package_nonexistence(self) -> None:
250250
required=True,
251251
)
252252

253-
def test_toplevel_module_not_pyfile(self):
253+
def test_toplevel_module_not_pyfile(self) -> None:
254254
Path.mkdir(Path("foo"), exist_ok=True)
255255
Path.mkdir(Path("foo/bar-1.0.0.dist-info"), exist_ok=True)
256256
Path.touch(Path("foo/bar.so"), exist_ok=True)

0 commit comments

Comments
 (0)