Skip to content

Commit

Permalink
Continued to revert classes
Browse files Browse the repository at this point in the history
  • Loading branch information
CulmoneY committed Sep 24, 2024
1 parent cd3aa97 commit 3ddb726
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 12 deletions.
12 changes: 6 additions & 6 deletions tests/test_contracts/test_contracts.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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.
Expand All @@ -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.
Expand Down Expand Up @@ -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.
Expand All @@ -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.
Expand Down
Original file line number Diff line number Diff line change
@@ -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]
Expand All @@ -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 = {}
4 changes: 2 additions & 2 deletions tests/test_custom_checkers/test_type_annotation_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions tests/test_validate_invariants.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

from __future__ import annotations

from typing import List

import pytest

from python_ta.contracts import check_contracts, validate_invariants
Expand All @@ -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
Expand Down

0 comments on commit 3ddb726

Please sign in to comment.