Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 7 additions & 14 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ known_third_party = ["poetry.core._vendor"]
strict = true
explicit_package_bases = true
namespace_packages = true
show_error_codes = true
mypy_path = "src"
files = "src, tests"
exclude = "(?x)(^tests/.*/fixtures | ^src/poetry/core/_vendor)"
Expand All @@ -82,6 +83,7 @@ module = [
'lark.*',
'setuptools.*',
'tomlkit.*',
'virtualenv.*',
]
ignore_missing_imports = true

Expand All @@ -107,23 +109,14 @@ module = [
'poetry.core.version.pep440.parser',
'poetry.core.version.pep440.segments',
'poetry.core.version.pep440.version',
# test modules
'tests.conftest',
'tests.integration.test_pep517',
'tests.json.*',
'tests.masonry.*',
'tests.packages.*',
'tests.pyproject.*',
'tests.semver.*',
'tests.spdx.*',
'tests.test_factory',
'tests.testutils.*',
'tests.utils.*',
'tests.vcs.*',
'tests.version.*',
]
ignore_errors = true

[[tool.mypy.overrides]]
module = ['tests.*']
# TODO: remove when mypy runs in environment with dependencies
disallow_untyped_decorators = false
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is only disabled due to pytest not currently being in mypy's environment

needs python-poetry/poetry#5279


[tool.vendoring]
destination = "src/poetry/core/_vendor/"
requirements = "src/poetry/core/_vendor/vendor.txt"
Expand Down
4 changes: 2 additions & 2 deletions src/poetry/core/masonry/builders/sdist.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from pprint import pformat
from tarfile import TarInfo
from typing import TYPE_CHECKING
from typing import ContextManager
from typing import Iterator

from poetry.core.masonry.builders.builder import Builder
from poetry.core.masonry.builders.builder import BuildIncludeFile
Expand Down Expand Up @@ -213,7 +213,7 @@ def build_setup(self) -> bytes:
).encode()

@contextmanager
def setup_py(self) -> ContextManager[Path]:
def setup_py(self) -> Iterator[Path]:
setup = self._path / "setup.py"
has_setup = setup.exists()

Expand Down
8 changes: 4 additions & 4 deletions src/poetry/core/packages/package.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,10 @@ def __init__(
self._authors = []
self._maintainers = []

self.homepage = None
self.repository_url = None
self.documentation_url = None
self.keywords = []
self.homepage: str | None = None
self.repository_url: str | None = None
self.documentation_url: str | None = None
self.keywords: list[str] = []
self._license = None
self.readmes: tuple[Path, ...] = ()

Expand Down
2 changes: 1 addition & 1 deletion src/poetry/core/packages/utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ def group_markers(
return groups


def convert_markers(marker: BaseMarker) -> dict[str, list[tuple[str, str]]]:
def convert_markers(marker: BaseMarker) -> dict[str, list[list[tuple[str, str]]]]:
groups = group_markers([marker])

requirements = {}
Expand Down
12 changes: 6 additions & 6 deletions src/poetry/core/version/markers.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def is_any(self) -> bool:
def is_empty(self) -> bool:
return False

def validate(self, environment: dict[str, Any]) -> bool:
def validate(self, environment: dict[str, Any] | None) -> bool:
raise NotImplementedError()

def without_extras(self) -> BaseMarker:
Expand Down Expand Up @@ -96,7 +96,7 @@ def is_any(self) -> bool:
def is_empty(self) -> bool:
return False

def validate(self, environment: dict[str, Any]) -> bool:
def validate(self, environment: dict[str, Any] | None) -> bool:
return True

def without_extras(self) -> BaseMarker:
Expand Down Expand Up @@ -140,7 +140,7 @@ def is_any(self) -> bool:
def is_empty(self) -> bool:
return True

def validate(self, environment: dict[str, Any]) -> bool:
def validate(self, environment: dict[str, Any] | None) -> bool:
return False

def without_extras(self) -> BaseMarker:
Expand Down Expand Up @@ -274,7 +274,7 @@ def union(self, other: BaseMarker) -> BaseMarker:

return other.union(self)

def validate(self, environment: dict[str, Any]) -> bool:
def validate(self, environment: dict[str, Any] | None) -> bool:
if environment is None:
return True

Expand Down Expand Up @@ -505,7 +505,7 @@ def union_simplify(self, other: BaseMarker) -> BaseMarker | None:

return None

def validate(self, environment: dict[str, Any]) -> bool:
def validate(self, environment: dict[str, Any] | None) -> bool:
return all(m.validate(environment) for m in self._markers)

def without_extras(self) -> BaseMarker:
Expand Down Expand Up @@ -695,7 +695,7 @@ def union(self, other: BaseMarker) -> BaseMarker:

return MarkerUnion.of(*new_markers)

def validate(self, environment: dict[str, Any]) -> bool:
def validate(self, environment: dict[str, Any] | None) -> bool:
return any(m.validate(environment) for m in self._markers)

def without_extras(self) -> BaseMarker:
Expand Down
2 changes: 1 addition & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import annotations

import sys
import tempfile

from pathlib import Path
from typing import TYPE_CHECKING
Expand All @@ -11,7 +12,6 @@
import virtualenv

from poetry.core.factory import Factory
from tests.testutils import tempfile


if TYPE_CHECKING:
Expand Down
16 changes: 10 additions & 6 deletions tests/integration/test_pep517.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,18 @@
)
def test_pep517_check_poetry_managed(
request: FixtureRequest, getter: str, project: str
):
) -> None:
with temporary_project_directory(request.getfixturevalue(getter)(project)) as path:
assert project_wheel_metadata(path)


def test_pep517_check(project_source_root: Path):
def test_pep517_check(project_source_root: Path) -> None:
assert project_wheel_metadata(str(project_source_root))


def test_pep517_build_sdist(temporary_directory: Path, project_source_root: Path):
def test_pep517_build_sdist(
temporary_directory: Path, project_source_root: Path
) -> None:
build_package(
srcdir=str(project_source_root),
outdir=str(temporary_directory),
Expand All @@ -48,7 +50,9 @@ def test_pep517_build_sdist(temporary_directory: Path, project_source_root: Path
assert len(distributions) == 1


def test_pep517_build_wheel(temporary_directory: Path, project_source_root: Path):
def test_pep517_build_wheel(
temporary_directory: Path, project_source_root: Path
) -> None:
build_package(
srcdir=str(project_source_root),
outdir=str(temporary_directory),
Expand All @@ -58,7 +62,7 @@ def test_pep517_build_wheel(temporary_directory: Path, project_source_root: Path
assert len(distributions) == 1


def test_pip_wheel_build(temporary_directory: Path, project_source_root: Path):
def test_pip_wheel_build(temporary_directory: Path, project_source_root: Path) -> None:
tmp = str(temporary_directory)
pip = subprocess_run(
"pip", "wheel", "--use-pep517", "-w", tmp, str(project_source_root)
Expand All @@ -71,7 +75,7 @@ def test_pip_wheel_build(temporary_directory: Path, project_source_root: Path):
assert len(wheels) == 1


def test_pip_install_no_binary(python: str, project_source_root: Path):
def test_pip_install_no_binary(python: str, project_source_root: Path) -> None:
subprocess_run(
python,
"-m",
Expand Down
12 changes: 7 additions & 5 deletions tests/json/test_poetry_schema.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
from __future__ import annotations

from typing import Any

import pytest

from poetry.core.json import validate_object


@pytest.fixture
def base_object() -> dict:
def base_object() -> dict[str, Any]:
return {
"name": "myapp",
"version": "1.0.0",
Expand All @@ -17,7 +19,7 @@ def base_object() -> dict:


@pytest.fixture
def multi_url_object() -> dict:
def multi_url_object() -> dict[str, Any]:
return {
"name": "myapp",
"version": "1.0.0",
Expand All @@ -35,18 +37,18 @@ def multi_url_object() -> dict:
}


def test_path_dependencies(base_object: dict):
def test_path_dependencies(base_object: dict[str, Any]) -> None:
base_object["dependencies"].update({"foo": {"path": "../foo"}})
base_object["dev-dependencies"].update({"foo": {"path": "../foo"}})

assert len(validate_object(base_object, "poetry-schema")) == 0


def test_multi_url_dependencies(multi_url_object: dict):
def test_multi_url_dependencies(multi_url_object: dict[str, Any]) -> None:
assert len(validate_object(multi_url_object, "poetry-schema")) == 0


def test_multiline_description(base_object: dict):
def test_multiline_description(base_object: dict[str, Any]) -> None:
bad_description = "Some multi-\nline string"
base_object["description"] = bad_description

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from tests.masonry.builders.fixtures.excluded_subpackage.example import __version__


def test_version():
def test_version() -> None:
assert __version__ == "0.1.0"
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
extensions = [Extension("extended.extended", ["extended/extended.c"])]


def build():
def build() -> None:
distribution = Distribution({"name": "extended", "ext_modules": extensions})
distribution.package_dir = "extended"

Expand Down
30 changes: 17 additions & 13 deletions tests/masonry/builders/test_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from pytest_mock import MockerFixture


def test_builder_find_excluded_files(mocker: MockerFixture):
def test_builder_find_excluded_files(mocker: MockerFixture) -> None:
p = mocker.patch("poetry.core.vcs.git.Git.get_ignored_files")
p.return_value = []

Expand All @@ -31,7 +31,7 @@ def test_builder_find_excluded_files(mocker: MockerFixture):
sys.platform == "win32",
reason="Windows is case insensitive for the most part",
)
def test_builder_find_case_sensitive_excluded_files(mocker: MockerFixture):
def test_builder_find_case_sensitive_excluded_files(mocker: MockerFixture) -> None:
p = mocker.patch("poetry.core.vcs.git.Git.get_ignored_files")
p.return_value = []

Expand All @@ -56,7 +56,9 @@ def test_builder_find_case_sensitive_excluded_files(mocker: MockerFixture):
sys.platform == "win32",
reason="Windows is case insensitive for the most part",
)
def test_builder_find_invalid_case_sensitive_excluded_files(mocker: MockerFixture):
def test_builder_find_invalid_case_sensitive_excluded_files(
mocker: MockerFixture,
) -> None:
p = mocker.patch("poetry.core.vcs.git.Git.get_ignored_files")
p.return_value = []

Expand All @@ -69,7 +71,7 @@ def test_builder_find_invalid_case_sensitive_excluded_files(mocker: MockerFixtur
assert {"my_package/Bar/foo/bar/Foo.py"} == builder.find_excluded_files()


def test_get_metadata_content():
def test_get_metadata_content() -> None:
builder = Builder(
Factory().create_poetry(Path(__file__).parent / "fixtures" / "complete")
)
Expand Down Expand Up @@ -122,7 +124,7 @@ def test_get_metadata_content():
]


def test_metadata_homepage_default():
def test_metadata_homepage_default() -> None:
builder = Builder(
Factory().create_poetry(Path(__file__).parent / "fixtures" / "simple_version")
)
Expand All @@ -132,7 +134,7 @@ def test_metadata_homepage_default():
assert metadata["Home-page"] is None


def test_metadata_with_vcs_dependencies():
def test_metadata_with_vcs_dependencies() -> None:
builder = Builder(
Factory().create_poetry(
Path(__file__).parent / "fixtures" / "with_vcs_dependency"
Expand All @@ -146,7 +148,7 @@ def test_metadata_with_vcs_dependencies():
assert requires_dist == "cleo @ git+https://github.com/sdispater/cleo.git@master"


def test_metadata_with_url_dependencies():
def test_metadata_with_url_dependencies() -> None:
builder = Builder(
Factory().create_poetry(
Path(__file__).parent / "fixtures" / "with_url_dependency"
Expand All @@ -164,7 +166,7 @@ def test_metadata_with_url_dependencies():
)


def test_missing_script_files_throws_error():
def test_missing_script_files_throws_error() -> None:
builder = Builder(
Factory().create_poetry(
Path(__file__).parent / "fixtures" / "script_reference_file_missing"
Expand All @@ -177,7 +179,7 @@ def test_missing_script_files_throws_error():
assert "is not found." in err.value.args[0]


def test_invalid_script_files_definition():
def test_invalid_script_files_definition() -> None:
with pytest.raises(RuntimeError) as err:
Builder(
Factory().create_poetry(
Expand All @@ -197,7 +199,7 @@ def test_invalid_script_files_definition():
"script_callable_legacy_table",
],
)
def test_entrypoint_scripts_legacy_warns(fixture: str):
def test_entrypoint_scripts_legacy_warns(fixture: str) -> None:
with pytest.warns(DeprecationWarning):
Builder(
Factory().create_poetry(Path(__file__).parent / "fixtures" / fixture)
Expand Down Expand Up @@ -236,7 +238,9 @@ def test_entrypoint_scripts_legacy_warns(fixture: str):
],
)
@pytest.mark.filterwarnings("ignore::DeprecationWarning")
def test_builder_convert_entry_points(fixture: str, result: dict[str, list[str]]):
def test_builder_convert_entry_points(
fixture: str, result: dict[str, list[str]]
) -> None:
entry_points = Builder(
Factory().create_poetry(Path(__file__).parent / "fixtures" / fixture)
).convert_entry_points()
Expand Down Expand Up @@ -264,13 +268,13 @@ def test_builder_convert_entry_points(fixture: str, result: dict[str, list[str]]
),
],
)
def test_builder_convert_script_files(fixture: str, result: list[Path]):
def test_builder_convert_script_files(fixture: str, result: list[Path]) -> None:
project_root = Path(__file__).parent / "fixtures" / fixture
script_files = Builder(Factory().create_poetry(project_root)).convert_script_files()
assert [p.relative_to(project_root) for p in script_files] == result


def test_metadata_with_readme_files():
def test_metadata_with_readme_files() -> None:
test_path = Path(__file__).parent.parent.parent / "fixtures" / "with_readme_files"
builder = Builder(Factory().create_poetry(test_path))

Expand Down
Loading