Skip to content

Commit

Permalink
Fix type errors
Browse files Browse the repository at this point in the history
  • Loading branch information
WangGithubUser committed Aug 21, 2023
1 parent 12d9935 commit a1ddd8f
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
5 changes: 5 additions & 0 deletions client/configuration/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,8 @@ def __init__(self, message: str) -> None:
class InvalidPythonVersion(InvalidConfiguration):
def __init__(self, message: str) -> None:
super().__init__(message)


class InvalidPackage(ValueError):
def __init__(self, pkg_name: str):
super().__init__(f"Invalid package: {pkg_name} does not exist.")

Check failure

Code scanning / Pyre

Missing return annotation Error

Missing return annotation [3]: Returning None but no return type is specified.
15 changes: 9 additions & 6 deletions client/configuration/search_path.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@
LOG: logging.Logger = logging.getLogger(__name__)

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

_PYCACHE = re.compile("__pycache__")
_PYCACHE: re.Pattern[str] = re.compile("__pycache__")


def _expand_relative_root(path: str, relative_root: str) -> str:
Expand Down Expand Up @@ -78,7 +78,7 @@ class SitePackageElement(Element):
package_name: str
is_toplevel_module: bool = False

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

Expand All @@ -97,9 +97,12 @@ def package_path(self) -> Union[str, None]:
dist_info_path = f"{self.site_root}/{directory}"
break
else:
return None
raise exceptions.InvalidPackage(self.package_name)

not_toplevel_patterns: Tuple[re.Pattern] = (this_pkg_filter, _PYCACHE)
not_toplevel_patterns: Tuple[re.Pattern[str], re.Pattern[str]] = (
this_pkg_filter,
_PYCACHE,
)

with open(file=f"{dist_info_path}/RECORD", mode="r") as record:

Check failure

Code scanning / Pyre

Uninitialized local Error

Uninitialized local [61]: Local variable dist\_info\_path is undefined, or not always defined.
files = []
Expand All @@ -114,7 +117,7 @@ def package_path(self) -> Union[str, None]:
else:
return file

return None
raise exceptions.InvalidPackage(self.package_name)

def path(self) -> str:
return os.path.join(self.site_root, self.package_path())
Expand Down
2 changes: 1 addition & 1 deletion client/configuration/tests/search_path_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ def test_process_required_raw_elements_site_package_nonexistence(self) -> None:
required=True,
)

def test_toplevel_module_not_pyfile(self):
def test_toplevel_module_not_pyfile(self) -> None:
Path.mkdir(Path("foo"), exist_ok=True)
Path.mkdir(Path("foo/bar-1.0.0.dist-info"), exist_ok=True)
Path.touch(Path("foo/bar.so"), exist_ok=True)
Expand Down

0 comments on commit a1ddd8f

Please sign in to comment.