Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix check_contracts handling of forward references in type annotations #941

Merged

Conversation

david-yz-liu
Copy link
Contributor

@david-yz-liu david-yz-liu commented Aug 11, 2023

Motivation and Context

A recent change caused @check_contracts to evaluate instance attribute type annotations when the class definition was first reached, which raised an error when the type annotations had forward references. One example is for linked list nodes:

@check_contracts
class Node:
    item: Any
    next: Optional[Node]

Your Changes

Description: Delay evaluate of the class type annotations until the first time an attribute is set (or a method is called).

Type of change (select all that apply):

  • Bug fix (non-breaking change which fixes an issue)

Testing

Added test cases and manual testing.

Questions and Comments (if applicable)

Checklist

  • I have performed a self-review of my own code.
  • I have verified that the CI tests have passed.
  • I have reviewed the test coverage changes reported on Coveralls.
  • I have added tests for my changes.
  • I have updated the CHANGELOG.md file.

@david-yz-liu david-yz-liu merged commit 81f04dc into pyta-uoft:master Aug 11, 2023
7 checks passed
@david-yz-liu david-yz-liu deleted the fix-forward-ref-contract-checking branch August 11, 2023 02:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant