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 distinct error codes test #73

Merged
merged 4 commits into from
Sep 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions tests/test_torchfix.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ def test_errorcodes_distinct():
LOGGER.info("Checking error code for %s", visitor.__class__.__name__)
errors = visitor.ERRORS
for e in errors:
assert e not in seen
seen.add(e)
assert e.error_code not in seen
seen.add(e.error_code)


def test_parse_error_code_str():
Expand Down
22 changes: 4 additions & 18 deletions torchfix/visitors/vision/singleton_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,8 @@ class TorchVisionSingletonImportVisitor(TorchVisitor):
TorchError(
"TOR203",
(
"Consider replacing 'import torchvision.datasets as datasets' "
"with 'from torchvision import datasets'."
),
),
TorchError(
"TOR203",
(
"Consider replacing 'import torchvision.models as models' "
"with 'from torchvision import models'."
),
),
TorchError(
"TOR203",
(
"Consider replacing 'import torchvision.transforms as transforms' "
"with 'from torchvision import transforms'."
"Consider replacing 'import torchvision.{module} as {module}' "
"with 'from torchvision import {module}'."
),
),
]
Expand Down Expand Up @@ -53,8 +39,8 @@ def visit_Import(self, node: cst.Import) -> None:
)
self.add_violation(
node,
error_code=self.ERRORS[i].error_code,
message=self.ERRORS[i].message(),
error_code=self.ERRORS[0].error_code,
message=self.ERRORS[0].message(module=import_attr),
replacement=replacement,
)
break