diff --git a/tests/test_contracts/test_contracts.py b/tests/test_contracts/test_contracts.py index 77801f8f..34f970a2 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 57c9ef01..10bd78f1 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 3eb4b553..746a62b2 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 bec5d376..e4150372 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