Commit 1af6e238 by David Hotham Committed by GitHub

strict flake8-type-checking (#6866)

recent flake8-type-checking encourages cast() using the name of the
class rather than the actual class, presumably with the aim that you
might find more things you don't need to import at runtime

however here, consistent with other recent MRs, I've taken the view that
it's better to assert that you have the expected type than to trust that
it's so
parent c9e6d5e4
...@@ -6,7 +6,7 @@ ban-relative-imports = true ...@@ -6,7 +6,7 @@ ban-relative-imports = true
format-greedy = 1 format-greedy = 1
inline-quotes = double inline-quotes = double
enable-extensions = TC, TC1 enable-extensions = TC, TC1
type-checking-exempt-modules = typing, typing-extensions type-checking-strict = true
eradicate-whitelist-extend = ^-.*; eradicate-whitelist-extend = ^-.*;
extend-ignore = extend-ignore =
# E203: Whitespace before ':' (pycqa/pycodestyle#373) # E203: Whitespace before ':' (pycqa/pycodestyle#373)
......
...@@ -40,7 +40,7 @@ repos: ...@@ -40,7 +40,7 @@ repos:
- flake8-quotes==3.3.1 - flake8-quotes==3.3.1
- flake8-simplify==0.19.3 - flake8-simplify==0.19.3
- flake8-tidy-imports==4.8.0 - flake8-tidy-imports==4.8.0
- flake8-type-checking==2.1.2 - flake8-type-checking==2.2.0
- flake8-typing-imports==1.12.0 - flake8-typing-imports==1.12.0
- flake8-use-fstring==1.4 - flake8-use-fstring==1.4
- pep8-naming==0.13.1 - pep8-naming==0.13.1
......
...@@ -257,7 +257,8 @@ class Factory(BaseFactory): ...@@ -257,7 +257,8 @@ class Factory(BaseFactory):
constraint["optional"] = True constraint["optional"] = True
if len(constraint) == 1 and "version" in constraint: if len(constraint) == 1 and "version" in constraint:
constraint = cast(str, constraint["version"]) assert isinstance(constraint["version"], str)
constraint = constraint["version"]
elif not constraint: elif not constraint:
constraint = "*" constraint = "*"
......
...@@ -13,7 +13,6 @@ from pathlib import Path ...@@ -13,7 +13,6 @@ from pathlib import Path
from subprocess import CalledProcessError from subprocess import CalledProcessError
from typing import TYPE_CHECKING from typing import TYPE_CHECKING
from typing import Any from typing import Any
from typing import cast
from cleo.io.null_io import NullIO from cleo.io.null_io import NullIO
from poetry.core.packages.file_dependency import FileDependency from poetry.core.packages.file_dependency import FileDependency
...@@ -771,7 +770,8 @@ class Executor: ...@@ -771,7 +770,8 @@ class Executor:
for dist in self._env.site_packages.distributions( for dist in self._env.site_packages.distributions(
name=package.name, writable_only=True name=package.name, writable_only=True
): ):
dist_path = cast(Path, dist._path) # type: ignore[attr-defined] dist_path = dist._path # type: ignore[attr-defined]
assert isinstance(dist_path, Path)
url = dist_path / "direct_url.json" url = dist_path / "direct_url.json"
url.write_text(json.dumps(url_reference), encoding="utf-8") url.write_text(json.dumps(url_reference), encoding="utf-8")
......
from __future__ import annotations from __future__ import annotations
from typing import TYPE_CHECKING from typing import TYPE_CHECKING
from typing import cast
from poetry.core.constraints.version import parse_constraint from poetry.core.constraints.version import parse_constraint
...@@ -114,7 +113,8 @@ class _Writer: ...@@ -114,7 +113,8 @@ class _Writer:
conjunction = "So," if conclusion or incompatibility == self._root else "And" conjunction = "So," if conclusion or incompatibility == self._root else "And"
incompatibility_string = str(incompatibility) incompatibility_string = str(incompatibility)
cause: ConflictCause = cast(ConflictCause, incompatibility.cause) cause = incompatibility.cause
assert isinstance(cause, ConflictCause)
if isinstance(cause.conflict.cause, ConflictCause) and isinstance( if isinstance(cause.conflict.cause, ConflictCause) and isinstance(
cause.other.cause, ConflictCause cause.other.cause, ConflictCause
...@@ -198,7 +198,8 @@ class _Writer: ...@@ -198,7 +198,8 @@ class _Writer:
numbered=numbered, numbered=numbered,
) )
elif self._is_collapsible(derived): elif self._is_collapsible(derived):
derived_cause: ConflictCause = cast(ConflictCause, derived.cause) derived_cause = derived.cause
assert isinstance(derived_cause, ConflictCause)
if isinstance(derived_cause.conflict.cause, ConflictCause): if isinstance(derived_cause.conflict.cause, ConflictCause):
collapsed_derived = derived_cause.conflict collapsed_derived = derived_cause.conflict
collapsed_ext = derived_cause.other collapsed_ext = derived_cause.other
...@@ -233,7 +234,8 @@ class _Writer: ...@@ -233,7 +234,8 @@ class _Writer:
if self._derivations[incompatibility] > 1: if self._derivations[incompatibility] > 1:
return False return False
cause: ConflictCause = cast(ConflictCause, incompatibility.cause) cause = incompatibility.cause
assert isinstance(cause, ConflictCause)
if isinstance(cause.conflict.cause, ConflictCause) and isinstance( if isinstance(cause.conflict.cause, ConflictCause) and isinstance(
cause.other.cause, ConflictCause cause.other.cause, ConflictCause
): ):
......
...@@ -12,7 +12,6 @@ from typing import TYPE_CHECKING ...@@ -12,7 +12,6 @@ from typing import TYPE_CHECKING
from typing import Any from typing import Any
from typing import Iterator from typing import Iterator
from typing import Mapping from typing import Mapping
from typing import cast
from poetry.utils.constants import REQUESTS_TIMEOUT from poetry.utils.constants import REQUESTS_TIMEOUT
...@@ -189,7 +188,8 @@ def _get_win_folder_from_registry(csidl_name: str) -> str: ...@@ -189,7 +188,8 @@ def _get_win_folder_from_registry(csidl_name: str) -> str:
) )
dir, type = _winreg.QueryValueEx(key, shell_folder_name) dir, type = _winreg.QueryValueEx(key, shell_folder_name)
return cast(str, dir) assert isinstance(dir, str)
return dir
def _get_win_folder_with_ctypes(csidl_name: str) -> str: def _get_win_folder_with_ctypes(csidl_name: str) -> str:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment