Skip to content

Commit

Permalink
fix: misc type errors (#4024)
Browse files Browse the repository at this point in the history
  • Loading branch information
danieleades authored Nov 13, 2021
1 parent 8786f1d commit a49372a
Show file tree
Hide file tree
Showing 24 changed files with 75 additions and 56 deletions.
1 change: 1 addition & 0 deletions poetry/console/commands/cache/list.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@ def handle(self) -> Optional[int]:
return 0

self.line("<warning>No caches found</>")
return None
3 changes: 2 additions & 1 deletion poetry/console/commands/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,8 @@ def handle(self) -> Optional[int]:
unique_config_values = self.unique_config_values
if setting_key in unique_config_values:
if self.option("unset"):
return config.config_source.remove_property(setting_key)
config.config_source.remove_property(setting_key)
return None

return self._handle_single_value(
config.config_source,
Expand Down
2 changes: 2 additions & 0 deletions poetry/console/commands/debug/resolve.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,3 +143,5 @@ def handle(self) -> Optional[int]:

table.set_rows(rows)
table.render()

return None
3 changes: 2 additions & 1 deletion poetry/console/commands/env/info.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,10 @@ def handle(self) -> Optional[int]:

self.line(str(env.path))

return
return None

self._display_complete_info(env)
return None

def _display_complete_info(self, env: "Env") -> None:
env_python_version = ".".join(str(s) for s in env.version_info[:3])
Expand Down
12 changes: 5 additions & 7 deletions poetry/console/commands/env_command.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
from typing import TYPE_CHECKING

from .command import Command
from typing import Optional

from poetry.utils.env import Env

if TYPE_CHECKING:
from poetry.utils.env import Env
from .command import Command


class EnvCommand(Command):
Expand All @@ -14,8 +12,8 @@ def __init__(self) -> None:
super(EnvCommand, self).__init__()

@property
def env(self) -> "Env":
def env(self) -> Optional[Env]:
return self._env

def set_env(self, env: "Env") -> None:
def set_env(self, env: Env) -> None:
self._env = env
5 changes: 3 additions & 2 deletions poetry/console/commands/init.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from typing import TYPE_CHECKING
from typing import Dict
from typing import List
from typing import Mapping
from typing import Optional
from typing import Tuple
from typing import Union
Expand Down Expand Up @@ -515,7 +516,7 @@ def _parse_requirements(self, requirements: List[str]) -> List[Dict[str, str]]:

def _format_requirements(
self, requirements: List[Dict[str, str]]
) -> Dict[str, Union[str, Dict[str, str]]]:
) -> Mapping[str, Union[str, Mapping[str, str]]]:
requires = {}
for requirement in requirements:
name = requirement.pop("name")
Expand All @@ -536,7 +537,7 @@ def _validate_author(self, author: str, default: str) -> Optional[str]:
author = author or default

if author in ["n", "no"]:
return
return None

m = AUTHOR_REGEX.match(author)
if not m:
Expand Down
2 changes: 2 additions & 0 deletions poetry/console/commands/publish.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,5 @@ def handle(self) -> Optional[int]:
client_cert,
self.option("dry-run"),
)

return None
1 change: 1 addition & 0 deletions poetry/console/commands/show.py
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,7 @@ def handle(self) -> Optional[int]:
line += " " + description

self.line(line)
return None

def display_package_tree(
self, io: "IO", package: "Package", installed_repo: "Repository"
Expand Down
4 changes: 3 additions & 1 deletion poetry/inspection/info.py
Original file line number Diff line number Diff line change
Expand Up @@ -397,11 +397,12 @@ def from_metadata(cls, path: Path) -> Optional["PackageInfo"]:
# handle PKG-INFO in unpacked sdist root
dist = pkginfo.UnpackedSDist(path.as_posix())
except ValueError:
return
return None

info = cls._from_distribution(dist=dist)
if info:
return info
return None

@classmethod
def from_package(cls, package: Package) -> "PackageInfo":
Expand Down Expand Up @@ -432,6 +433,7 @@ def _get_poetry_package(path: Path) -> Optional[ProjectPackage]:
# TODO: add support for handling non-poetry PEP-517 builds
if PyProjectTOML(path.joinpath("pyproject.toml")).is_poetry_project():
return Factory().create_poetry(path).package
return None

@classmethod
def _pep517_metadata(cls, path: Path) -> "PackageInfo":
Expand Down
7 changes: 4 additions & 3 deletions poetry/installation/installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from typing import Iterable
from typing import List
from typing import Optional
from typing import Sequence
from typing import Union

from cleo.io.io import IO
Expand Down Expand Up @@ -499,7 +500,7 @@ def _execute_uninstall(self, operation: Uninstall) -> None:
self._installer.remove(operation.package)

def _populate_local_repo(
self, local_repo: Repository, ops: List[Operation]
self, local_repo: Repository, ops: Sequence[Operation]
) -> None:
for op in ops:
if isinstance(op, Uninstall):
Expand All @@ -514,7 +515,7 @@ def _populate_local_repo(

def _get_operations_from_lock(
self, locked_repository: Repository
) -> List[Operation]:
) -> Sequence[Operation]:
installed_repo = self._installed_repository
ops = []

Expand Down Expand Up @@ -543,7 +544,7 @@ def _get_operations_from_lock(

return ops

def _filter_operations(self, ops: List[Operation], repo: Repository) -> None:
def _filter_operations(self, ops: Sequence[Operation], repo: Repository) -> None:
extra_packages = self._get_extra_packages(repo)
for op in ops:
if isinstance(op, Update):
Expand Down
23 changes: 12 additions & 11 deletions poetry/mixology/incompatibility.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from typing import Callable
from typing import Dict
from typing import Iterator
from typing import List
Expand Down Expand Up @@ -272,18 +273,18 @@ def _try_requires_both(
other_line: Optional[int],
) -> Optional[str]:
if len(self._terms) == 1 or len(other.terms) == 1:
return
return None

this_positive = self._single_term_where(lambda term: term.is_positive())
if this_positive is None:
return
return None

other_positive = other._single_term_where(lambda term: term.is_positive())
if other_positive is None:
return
return None

if this_positive.dependency != other_positive.dependency:
return
return None

this_negatives = " or ".join(
[self._terse(term) for term in self._terms if not term.is_positive()]
Expand Down Expand Up @@ -318,13 +319,13 @@ def _try_requires_through(
self, other: "Incompatibility", details: dict, this_line: int, other_line: int
) -> Optional[str]:
if len(self._terms) == 1 or len(other.terms) == 1:
return
return None

this_negative = self._single_term_where(lambda term: not term.is_positive())
other_negative = other._single_term_where(lambda term: not term.is_positive())

if this_negative is None and other_negative is None:
return
return None

this_positive = self._single_term_where(lambda term: term.is_positive())
other_positive = self._single_term_where(lambda term: term.is_positive())
Expand Down Expand Up @@ -352,7 +353,7 @@ def _try_requires_through(
latter = self
latter_line = this_line
else:
return
return None

prior_positives = [term for term in prior.terms if term.is_positive()]

Expand Down Expand Up @@ -411,10 +412,10 @@ def _try_requires_forbidden(

negative = prior._single_term_where(lambda term: not term.is_positive())
if negative is None:
return
return None

if not negative.inverse.satisfies(latter.terms[0]):
return
return None

positives = [t for t in prior.terms if t.is_positive()]

Expand Down Expand Up @@ -459,14 +460,14 @@ def _terse(self, term: Term, allow_every: bool = False) -> str:
term.dependency.pretty_name, term.dependency.pretty_constraint
)

def _single_term_where(self, callable: callable) -> Optional[Term]:
def _single_term_where(self, callable: Callable[[Term], bool]) -> Optional[Term]:
found = None
for term in self._terms:
if not callable(term):
continue

if found is not None:
return
return None

found = term

Expand Down
4 changes: 2 additions & 2 deletions poetry/mixology/term.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ def intersect(self, other: "Term") -> Optional["Term"]:
elif self.is_positive() != other.is_positive():
return self if self.is_positive() else other
else:
return
return None

def difference(self, other: "Term") -> "Term":
"""
Expand All @@ -158,7 +158,7 @@ def _non_empty_term(
self, constraint: "VersionTypes", is_positive: bool
) -> Optional["Term"]:
if constraint.is_empty():
return
return None

return Term(self.dependency.with_constraint(constraint), is_positive)

Expand Down
14 changes: 7 additions & 7 deletions poetry/mixology/version_solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ def _propagate(self, package: str) -> None:

def _propagate_incompatibility(
self, incompatibility: Incompatibility
) -> Optional[Union[str, object]]:
) -> Union[str, object, None]:
"""
If incompatibility is almost satisfied by _solution, adds the
negation of the unsatisfied term to _solution.
Expand All @@ -154,12 +154,12 @@ def _propagate_incompatibility(
# If term is already contradicted by _solution, then
# incompatibility is contradicted as well and there's nothing new we
# can deduce from it.
return
return None
elif relation == SetRelation.OVERLAPPING:
# If more than one term is inconclusive, we can't deduce anything about
# incompatibility.
if unsatisfied is not None:
return
return None

# If exactly one term in incompatibility is inconclusive, then it's
# almost satisfied and [term] is the unsatisfied term. We can add the
Expand Down Expand Up @@ -324,7 +324,7 @@ def _choose_package_version(self) -> Optional[str]:
"""
unsatisfied = self._solution.unsatisfied
if not unsatisfied:
return
return None

# Prefer packages with as few remaining versions as possible,
# so that if a conflict is necessary it's forced quickly.
Expand Down Expand Up @@ -449,14 +449,14 @@ def _add_incompatibility(self, incompatibility: Incompatibility) -> None:

def _get_locked(self, dependency: Dependency) -> Optional[Package]:
if dependency.name in self._use_latest:
return
return None

locked = self._locked.get(dependency.name)
if not locked:
return
return None

if not dependency.is_same_package_as(locked):
return
return None

return locked

Expand Down
2 changes: 1 addition & 1 deletion poetry/packages/project_package.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
class ProjectPackage(_ProjectPackage):
def set_version(
self, version: Union[str, "Version"], pretty_version: Optional[str] = None
) -> "ProjectPackage":
) -> None:
from poetry.core.semver.version import Version # noqa

if not isinstance(version, Version):
Expand Down
2 changes: 1 addition & 1 deletion poetry/puzzle/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def load_deferred(self, load_deferred: bool) -> None:
self._load_deferred = load_deferred

@contextmanager
def use_environment(self, env: Env) -> "Provider":
def use_environment(self, env: Env) -> Iterator["Provider"]:
original_env = self._env
original_python_constraint = self._python_constraint

Expand Down
3 changes: 2 additions & 1 deletion poetry/puzzle/solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from typing import Callable
from typing import Dict
from typing import FrozenSet
from typing import Iterator
from typing import List
from typing import Optional
from typing import Tuple
Expand Down Expand Up @@ -65,7 +66,7 @@ def provider(self) -> Provider:
return self._provider

@contextmanager
def use_environment(self, env: Env) -> None:
def use_environment(self, env: Env) -> Iterator[None]:
with self.provider.use_environment(env):
yield

Expand Down
8 changes: 4 additions & 4 deletions poetry/repositories/legacy_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,14 +144,14 @@ def link_version(self, link: Link) -> Optional[Version]:
info, ext = link.splitext()
match = self.VERSION_REGEX.match(info)
if not match:
return
return None

version = match.group(2)

try:
version = Version.parse(version)
except ValueError:
return
return None

return version

Expand Down Expand Up @@ -428,9 +428,9 @@ def _get(self, endpoint: str) -> Optional[Page]:
f"Authorization error accessing {url}",
level="warning",
)
return
return None
if response.status_code == 404:
return
return None
response.raise_for_status()
except requests.HTTPError as e:
raise RepositoryError(e)
Expand Down
2 changes: 1 addition & 1 deletion poetry/repositories/repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def find_links_for_package(self, package: "Package") -> List["Link"]:
return []

def search(self, query: str) -> List["Package"]:
results = []
results: List["Package"] = []

for package in self.packages:
if query in package.name:
Expand Down
2 changes: 1 addition & 1 deletion poetry/utils/authenticator.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ def _get_http_auth(
else:
url = self._config.get(f"repositories.{name}.url")
if not url:
return
return None

parsed_url = urllib.parse.urlsplit(url)

Expand Down
Loading

0 comments on commit a49372a

Please sign in to comment.