Skip to content

Commit

Permalink
modified Classes to revert to older type annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
CulmoneY committed Sep 24, 2024
1 parent b4d4cc8 commit cd3aa97
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
6 changes: 3 additions & 3 deletions tests/test_contracts/test_class_contracts.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import math
from dataclasses import dataclass
from typing import List, Set
from typing import List, Set, Tuple

import pytest
from nested_preconditions_example import Student
Expand Down Expand Up @@ -385,7 +385,7 @@ class ThemedWidget:
primary_color: str
secondary_color: str

def __init__(self, theme: str, color_palette: tuple[str, str], options: dict = None) -> None:
def __init__(self, theme: str, color_palette: Tuple[str, str], options: dict = None) -> None:
if options:
self.setup_options(options)
else:
Expand All @@ -403,7 +403,7 @@ def setup_size(self, size: int) -> None:
def apply_theme(self, theme: str) -> None:
self.theme = theme

def apply_color_palette(self, color_palette: tuple[str, str]) -> None:
def apply_color_palette(self, color_palette: Tuple[str, str]) -> None:
self.primary_color, self.secondary_color = color_palette


Expand Down
11 changes: 6 additions & 5 deletions tests/test_contracts/test_contracts.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import annotations

import sys
from typing import Dict, List, Set

import pytest
from nested_preconditions_example import Student, my_function
Expand Down Expand Up @@ -33,7 +34,7 @@ def test_nullary_return_dict() -> None:
"""Calling a nullary function with the correct return type (dict)."""

@check_contracts
def nullary() -> dict[str, int]:
def nullary() -> Dict[str, int]:
return {"one": 1}

nullary()
Expand Down Expand Up @@ -74,7 +75,7 @@ def test_nullary_return_dict_wrong() -> None:
"""Calling a nullary function with the incorrect return type (dict)."""

@check_contracts
def nullary() -> dict[str, int]:
def nullary() -> Dict[str, int]:
return {1: 1}

with pytest.raises(AssertionError):
Expand Down Expand Up @@ -147,7 +148,7 @@ def nullary():


@check_contracts
def _my_sum(numbers: list[int]) -> int:
def _my_sum(numbers: List[int]) -> int:
return sum(numbers)


Expand Down Expand Up @@ -286,7 +287,7 @@ def is_even(lst: list[int]) -> bool:


@check_contracts
def _is_even_sum(numbers: list[int]) -> int:
def _is_even_sum(numbers: List[int]) -> int:
"""Return the sum of a list of numbers.
Precondition: is_even(numbers)
Expand All @@ -311,7 +312,7 @@ def test_is_even_sum_violation() -> None:


@check_contracts
def search(numbers: set[int]) -> bool:
def search(numbers: Set[int]) -> bool:
"""Search for a number in a set.
Illustrates a preconditions with a double comprehension.
Expand Down
5 changes: 4 additions & 1 deletion tests/test_subclass_contracts.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from __future__ import annotations

from typing import List

import pytest

from python_ta.contracts import check_all_contracts
Expand All @@ -9,6 +11,7 @@ class Employee:
"""
Represents an employee
Representation Invariants:
Representation Invariants:
- len(self.name) > 0
- self.wage >= 15
Expand Down Expand Up @@ -51,7 +54,7 @@ class Teacher(Employee):
- self.wage == self.wage_per_class * len(self.currently_teaching)
"""

currently_teaching: list[str]
currently_teaching: List[str]
wage_per_class: float

def __init__(self, name, wage_per_class, currently_teaching):
Expand Down

0 comments on commit cd3aa97

Please sign in to comment.