From a90621165ee05a9570aaa1923b5726ce934e88c0 Mon Sep 17 00:00:00 2001 From: Mauko Quiroga Date: Wed, 27 Sep 2023 16:27:16 +0200 Subject: [PATCH] Clarify type hints --- openfisca_core/entities/role.py | 2 +- .../entities/tests/test_group_entity.py | 20 +++---------------- openfisca_core/entities/tests/test_role.py | 17 ++-------------- 3 files changed, 6 insertions(+), 33 deletions(-) diff --git a/openfisca_core/entities/role.py b/openfisca_core/entities/role.py index 1ffa6ee95..ec8a2ce34 100644 --- a/openfisca_core/entities/role.py +++ b/openfisca_core/entities/role.py @@ -1,6 +1,6 @@ from __future__ import annotations -from collections.abc import Sequence, Mapping +from collections.abc import Mapping, Sequence from typing import Any import dataclasses diff --git a/openfisca_core/entities/tests/test_group_entity.py b/openfisca_core/entities/tests/test_group_entity.py index 882e77739..ed55648d7 100644 --- a/openfisca_core/entities/tests/test_group_entity.py +++ b/openfisca_core/entities/tests/test_group_entity.py @@ -8,50 +8,36 @@ @pytest.fixture def parent() -> str: - """A key.""" - return "parent" @pytest.fixture def uncle() -> str: - """Another key.""" - return "uncle" @pytest.fixture def first_parent() -> str: - """A sub-role.""" - return "first_parent" @pytest.fixture def second_parent() -> str: - """Another sub-role.""" - return "second_parent" @pytest.fixture def third_parent() -> str: - """Yet another sub-role.""" - return "third_parent" @pytest.fixture -def role(parent: str, first_parent: str, third_parent: str) -> Any: - """A role.""" - +def role(parent: str, first_parent: str, third_parent: str) -> Mapping[str, Any]: return {"key": parent, "subroles": {first_parent, third_parent}} @pytest.fixture def group_entity(role: Mapping[str, Any]) -> entities.GroupEntity: - """A group entity.""" - return entities.GroupEntity("key", "label", "plural", "doc", (role,)) @@ -68,7 +54,7 @@ def test_init_when_doc_indented() -> None: def test_group_entity_with_roles( group_entity: entities.GroupEntity, parent: str, uncle: str ) -> None: - """Assign a role for each role-like passed as argument.""" + """Assign a Role for each role-like passed as argument.""" assert hasattr(group_entity, parent.upper()) assert not hasattr(group_entity, uncle.upper()) @@ -77,7 +63,7 @@ def test_group_entity_with_roles( def test_group_entity_with_subroles( group_entity: entities.GroupEntity, first_parent: str, second_parent: str ) -> None: - """Assign a role for each sub-role-like passed as argument.""" + """Assign a Role for each subrole-like passed as argument.""" assert hasattr(group_entity, first_parent.upper()) assert not hasattr(group_entity, second_parent.upper()) diff --git a/openfisca_core/entities/tests/test_role.py b/openfisca_core/entities/tests/test_role.py index 13fda9465..83692e823 100644 --- a/openfisca_core/entities/tests/test_role.py +++ b/openfisca_core/entities/tests/test_role.py @@ -1,24 +1,11 @@ -from typing import Any - -import pytest - from openfisca_core import entities -from openfisca_core.entities.typing import Entity - - -@pytest.fixture -def entity() -> Any: - """An entity.""" - - return object() - -def test_init_when_doc_indented(entity: Entity) -> None: +def test_init_when_doc_indented() -> None: """De-indent the ``doc`` attribute if it is passed at initialisation.""" key = "\tkey" doc = "\tdoc" - role = entities.Role({"key": key, "doc": doc}, entity) + role = entities.Role({"key": key, "doc": doc}, object()) assert role.key == key assert role.doc == doc.lstrip()