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

Don't throw e9999 for local imports #959

Merged
merged 18 commits into from
Jan 2, 2024

Conversation

ChristopherLi05
Copy link
Contributor

@ChristopherLi05 ChristopherLi05 commented Sep 25, 2023

Motivation and Context

Addresses #945

Your Changes

Description:

I added the get_local_files method to python_ta/checkers/forbidden_import_checker.py#ForbiddenImportChecker which gets all of the python files in the same directory as the file that the linter is currently checking. I then modified visit_import, visit_importfrom, and visit_call to use this function so the checker won't throw an error when importing local files.

I updated examples/custom_checkers/e9999_forbidden_import.py to add the line import e9999_forbidden_import_local # No error.

I created examples/custom_checkers/e9999_forbidden_import_local.py to demonstrate local file importing.

Type of change (select all that apply):

  • Breaking change (fix or feature that would cause existing functionality to change)
  • Test update (change that modifies or updates tests only)

The checker will no longer throw an e9999 error when importing a local file.

Testing

I ran python -m pytest tests to make sure I didn't mess the preexisting tests up.

I then ran the following code to make sure that python_ta wouldn't throw an e9999 error on line 4.

import python_ta
python_ta.check_all("examples/custom_checkers/e9999_forbidden_import")

Questions and Comments (if applicable)

Where is the test function/file for the forbidden_import_checker?

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.

@ChristopherLi05 ChristopherLi05 changed the title Local imports Don't throw e9999 for local imports Sep 25, 2023
@coveralls
Copy link
Collaborator

coveralls commented Oct 8, 2023

Pull Request Test Coverage Report for Build 7234281424

  • 21 of 21 (100.0%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.03%) to 94.831%

Totals Coverage Status
Change from base Build 7214204275: 0.03%
Covered Lines: 3449
Relevant Lines: 3637

💛 - 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.

Hi @ChristopherLi05! Thanks for making this PR, and sorry for the veyr long delay in considering it.

Ultimately, the current behaviour of PythonTA is the preferred default. However, I would support adding a new boolean configuration option, allow-local-imports, which provides users the option of allowing local imports. If you're interested in pursuing this, you can take a look at the other custom configuration options PythonTA supports; see, for example, #973.

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.

Thanks very much, @ChristopherLi05!

@david-yz-liu david-yz-liu merged commit 23acf04 into pyta-uoft:master Jan 2, 2024
15 checks passed
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