From 3ddb726a15af05e4e4358ba5214d6516d3ab0231 Mon Sep 17 00:00:00 2001 From: CulmoneY Date: Tue, 24 Sep 2024 17:24:05 -0400 Subject: [PATCH] Continued to revert classes --- tests/test_contracts/test_contracts.py | 12 ++++++------ .../test_contracts_type_alias_abstract_network.py | 4 ++-- .../test_type_annotation_checker.py | 4 ++-- tests/test_validate_invariants.py | 6 ++++-- 4 files changed, 14 insertions(+), 12 deletions(-) diff --git a/tests/test_contracts/test_contracts.py b/tests/test_contracts/test_contracts.py index 77801f8fd..34f970a22 100644 --- a/tests/test_contracts/test_contracts.py +++ b/tests/test_contracts/test_contracts.py @@ -243,7 +243,7 @@ def parameter_int(num: int) -> None: @check_contracts -def _my_sum_one_precondition(numbers: list[int]) -> int: +def _my_sum_one_precondition(numbers: List[int]) -> int: """Return the sum of a list of numbers. Precondition: len(numbers) > 2 @@ -402,7 +402,7 @@ def test_invalid_typing_generic_argument() -> None: """ @check_contracts - def unary(arg: list[str]) -> None: + def unary(arg: List[str]) -> None: return with pytest.raises(AssertionError): @@ -455,7 +455,7 @@ def test_get_double_disabled_contract_checking(disable_contract_checking) -> Non # Test that postcondition checks involving function parameters pass and fail as expected @check_contracts -def _add_to_set_valid(num_set: set[int], new_num: int) -> None: +def _add_to_set_valid(num_set: Set[int], new_num: int) -> None: """ Add a number to the provided set if the number does not already exist in the set. @@ -467,7 +467,7 @@ def _add_to_set_valid(num_set: set[int], new_num: int) -> None: @check_contracts -def _add_to_set_invalid(num_set: set[int], new_num: int) -> None: +def _add_to_set_invalid(num_set: Set[int], new_num: int) -> None: """ Add new_num to the num_set. This is implemented incorrectly to make the postcondition check fail. @@ -498,7 +498,7 @@ def test_add_to_set_invalid() -> None: # Test that postcondition checks that use custom functions in scope pass and fail as expected @check_contracts -def _get_even_nums_valid(lst: list[int]) -> list[int]: +def _get_even_nums_valid(lst: List[int]) -> List[int]: """ Return a list of all even numbers in the input list. @@ -508,7 +508,7 @@ def _get_even_nums_valid(lst: list[int]) -> list[int]: @check_contracts -def _get_even_nums_invalid(lst: list[int]) -> list[int]: +def _get_even_nums_invalid(lst: List[int]) -> List[int]: """ Return a list of all odd numbers in the input list, which should cause the postcondition check to fail. diff --git a/tests/test_contracts/test_contracts_type_alias_abstract_network.py b/tests/test_contracts/test_contracts_type_alias_abstract_network.py index 57c9ef01a..10bd78f1a 100644 --- a/tests/test_contracts/test_contracts_type_alias_abstract_network.py +++ b/tests/test_contracts/test_contracts_type_alias_abstract_network.py @@ -1,6 +1,6 @@ from __future__ import annotations -from typing import Union +from typing import Dict, Union # This creates a type alias, to save us typing "Union[int, tuple]" everywhere NodeAddress = Union[int, tuple] @@ -20,7 +20,7 @@ def __init__(self, address: NodeAddress) -> None: # The AbstractNetwork class ############################################################################### class AbstractNetwork: - _nodes: dict[NodeAddress, Node] + _nodes: Dict[NodeAddress, Node] def __init__(self) -> None: self._nodes = {} diff --git a/tests/test_custom_checkers/test_type_annotation_checker.py b/tests/test_custom_checkers/test_type_annotation_checker.py index 3eb4b5535..746a62b26 100644 --- a/tests/test_custom_checkers/test_type_annotation_checker.py +++ b/tests/test_custom_checkers/test_type_annotation_checker.py @@ -12,11 +12,11 @@ def test_type_is_assigned_for_function(self): """Ensure that checker catches when type is assigned instead of annotated in function parameters.""" src = """ - from __future__ import annotations + from typing import List def add_two_numbers( x=int, # Error on this line - y=list[float], # Error on this line + y=List[float], # Error on this line z: type = complex # No error on this line ) -> int: return (x + y) * z diff --git a/tests/test_validate_invariants.py b/tests/test_validate_invariants.py index bec5d3761..e41503727 100644 --- a/tests/test_validate_invariants.py +++ b/tests/test_validate_invariants.py @@ -4,6 +4,8 @@ from __future__ import annotations +from typing import List + import pytest from python_ta.contracts import check_contracts, validate_invariants @@ -20,9 +22,9 @@ class Person: given_name: str age: int - friends: list[str] + friends: List[str] - def __init__(self, given_name: str, age: int, friends: list[str]) -> None: + def __init__(self, given_name: str, age: int, friends: List[str]) -> None: """Initialize a new Person object.""" self.given_name = given_name self.age = age