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

Replaced all instances of outdated type annotations (List, Dict, etc.…) #1081

Merged
merged 32 commits into from
Sep 27, 2024

Conversation

CulmoneY
Copy link
Contributor

@CulmoneY CulmoneY commented Sep 14, 2024

Proposed Changes

Updated the PythonTA codebase to use modern type annotations. Specifically, I replaced List with list, Dict with dict, Set with set, and Tuple with tuple. I addressed the following two requirements:

  1. Added from __future__ import annotations to the top of each file where these type annotations are used, if it wasn't present already.
  2. Removed any unused imports of List, Dict, Set, and Tuple to clean up the codebase.

Type of Change

(Write an X or a brief description next to the type or types that best describe your changes.)

Type Applies?
🚨 Breaking change (fix or feature that would cause existing functionality to change)
New feature (non-breaking change that adds functionality)
🐛 Bug fix (non-breaking change that fixes an issue)
♻️ Refactoring (internal change to codebase, without changing functionality) X
🚦 Test update (change that only adds or modifies tests)
📚 Documentation update (change that only updates documentation)
📦 Dependency update (change that updates a dependency)
🔧 Internal (change that only affects developers or continuous integration)

Checklist

(Complete each of the following items for your pull request. Indicate that you have completed an item by changing the [ ] into a [x] in the raw text, or by clicking on the checkbox in the rendered description on GitHub.)

Before opening your pull request:

  • I have performed a self-review of my changes.
    • Check that all changed files included in this pull request are intentional changes.
    • Check that all changes are relevant to the purpose of this pull request, as described above.
  • I have added tests for my changes, if applicable.
    • This is required for all bug fixes and new features.
  • I have updated the project documentation, if applicable.
    • This is required for new features.
  • I have updated the project Changelog (this is required for all changes).
  • If this is my first contribution, I have added myself to the list of contributors.

After opening your pull request:

  • I have verified that the pre-commit.ci checks have passed.
  • I have verified that the CI tests have passed.
  • I have reviewed the test coverage changes reported by Coveralls.
  • I have requested a review from a project maintainer.

…) with the current built-in types (list, dict, etc.) .
Copy link
Contributor

@david-yz-liu david-yz-liu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@CulmoneY okay good work, though overall you were a bit too broad with your find-and-replace (see inline comments).

In addition to the comments I left inline, I have two additional comments:

  1. You'll need to update your branch since I merged in @Raine-Yang-UofT's PR (see my message on Slack). There will be merge conflicts, so you have a good opportunity to practice resolving those.
  2. Update the Changelog. This is an internal change.

docs/checkers/index.md Outdated Show resolved Hide resolved
examples/ending_locations/subscript.py Show resolved Hide resolved
examples/ending_locations/subscript.py Outdated Show resolved Hide resolved
python_ta/checkers/forbidden_io_function_checker.py Outdated Show resolved Hide resolved
python_ta/checkers/forbidden_python_syntax_checker.py Outdated Show resolved Hide resolved
tests/test_cfg/test_cfg_generator.py Outdated Show resolved Hide resolved
@@ -3,15 +3,15 @@
# Default max amount of messages for reporter to display.
pyta-number-of-messages = 10

# Set whether the default error messages by pylint should be overwritten by python TA's custom messages
# set whether the default error messages by pylint should be overwritten by python TA's custom messages
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't change this file

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure why you marked this comment as resolved; perhaps you meant to make this change, but either forgot or did not commit the change. Either way, please ensure that you double-check your work before resolving my comments, as I don't want to repeat comments.

tests/test_contracts/test_class_forward_reference.py Outdated Show resolved Hide resolved
tests/test_custom_checkers/test_type_annotation_checker.py Outdated Show resolved Hide resolved
@david-yz-liu
Copy link
Contributor

@CulmoneY oh sorry I realized you hadn't yet requested a review, so I may have been a bit premature! Well, keep working :)

@CulmoneY CulmoneY marked this pull request as draft September 15, 2024 20:23
@CulmoneY CulmoneY marked this pull request as ready for review September 15, 2024 21:22
@CulmoneY CulmoneY marked this pull request as draft September 16, 2024 01:21
@CulmoneY CulmoneY marked this pull request as ready for review September 16, 2024 01:21
python_ta/contracts/__init__.py Outdated Show resolved Hide resolved
python_ta/contracts/__init__.py Outdated Show resolved Hide resolved
@@ -478,7 +478,7 @@ def end_setter_from_source(source_code, pred, only_consumables=False):
def set_endings_from_source(node):
# Tuple nodes have an end_col_offset that includes the end paren,
# but their col_offset does not include the start paren.
# To address this, we override the Tuple node's end_col_offset.
# To address this, we override the tuple node's end_col_offset.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

revert this change

) -> List[z3.ExprRef]:
"""Convert an astroid List, Set, Tuple node to a list of z3 expressions."""
) -> list[z3.ExprRef]:
"""Convert an astroid list, Set, tuple node to a list of z3 expressions."""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Revert these changes

@@ -43,7 +43,7 @@ def create_cfg_funcs_only():

This fixture specifies that cfgs will only be created for functions.
"""
# Setup: store the paths of the files being used/created
# setup: store the paths of the files being used/created
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

revert this change

@@ -3,15 +3,15 @@
# Default max amount of messages for reporter to display.
pyta-number-of-messages = 10

# Set whether the default error messages by pylint should be overwritten by python TA's custom messages
# set whether the default error messages by pylint should be overwritten by python TA's custom messages
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure why you marked this comment as resolved; perhaps you meant to make this change, but either forgot or did not commit the change. Either way, please ensure that you double-check your work before resolving my comments, as I don't want to repeat comments.

@CulmoneY CulmoneY marked this pull request as draft September 19, 2024 22:20
@CulmoneY CulmoneY marked this pull request as ready for review September 23, 2024 16:54
@@ -25,7 +26,7 @@ class Person:

age: int
name: str
fav_foods: List[str]
fav_foods: list[str]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay so the tests on 3.8 are failing, and not just because of the flaky test we previously discussed. I realized that because 3.8 doesn't support the newer type annotations, we can't change these type annotations *for functions and classes that are used for contract-checking testing. This includes the functions/classes in this file and other files under tests/test_contracts. Please revert those changes.

@CulmoneY CulmoneY marked this pull request as draft September 24, 2024 18:04
@CulmoneY CulmoneY marked this pull request as ready for review September 25, 2024 02:18
@CulmoneY CulmoneY marked this pull request as draft September 25, 2024 02:18
@CulmoneY CulmoneY marked this pull request as ready for review September 25, 2024 02:21
@coveralls
Copy link
Collaborator

coveralls commented Sep 25, 2024

Pull Request Test Coverage Report for Build 11047801951

Details

  • 59 of 62 (95.16%) changed or added relevant lines in 16 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.001%) to 92.051%

Changes Missing Coverage Covered Lines Changed/Added Lines %
python_ta/contracts/main.py 0 3 0.0%
Totals Coverage Status
Change from base Build 11018465322: 0.001%
Covered Lines: 3057
Relevant Lines: 3321

💛 - Coveralls

Copy link
Contributor

@david-yz-liu david-yz-liu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@CulmoneY it's great to see that the tests are passing. I left a few more comments, but also it appears you haven't addressed all of the comments I left in my previous review. You should go through each of these carefully; one strategy to keep track of your progress is to use an emoji reaction to indicate when you've fixed (and committed) a change for a particular comment.

Don't resolve any comments until you've pushed your changes and verified that the issue is actually fixed (there was at least one instance I saw where you had resolved a comment but hadn't actually made the corresponding change).

@@ -9,6 +11,7 @@ class Employee:
"""
Represents an employee

Representation Invariants:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

delete this line

@@ -14,7 +14,6 @@ def test_type_is_assigned_for_function(self):
src = """
from typing import List


Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

revert this change

@CulmoneY
Copy link
Contributor Author

Hi David,

All the requested changes have been implemented. I double-checked everything to ensure that there are no unnecessary or incomplete modifications. However, I would like to apologize for any inconvenience caused by premature reviews. I converted my PR from draft status to run the tests, which is why some of your requested corrections weren't implemented at the time.

Moving forward, I’ll be more mindful to avoid this and ensure that my PR is fully ready before requesting a review.

Thank you for your understanding, and I appreciate your time and feedback.

Copy link
Contributor

@david-yz-liu david-yz-liu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@CulmoneY looks great! For future reference, you can unmark a PR as draft in order to trigger the CI tests, and that's a separate actions from "requesting a review" from me (the latter is a separate action on GitHub). This lets you run the CI tests without yet asking for me to review it.

@david-yz-liu david-yz-liu merged commit 2e3061a into pyta-uoft:master Sep 27, 2024
15 checks passed
@CulmoneY CulmoneY deleted the refactoring_type_annotations branch September 27, 2024 01:19
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.

3 participants