Skip to content

Commit

Permalink
change codemod metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
clavedeluna committed Feb 16, 2024
1 parent 7109776 commit 5f2813b
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 17 deletions.
10 changes: 5 additions & 5 deletions integration_tests/test_fix_task_instantiation.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
from core_codemods.fix_task_instantiation import FixTaskInstantiation
from core_codemods.fix_async_task_instantiation import FixAsyncTaskInstantiation
from integration_tests.base_test import (
BaseIntegrationTest,
original_and_expected_from_code_path,
)


class TestFixTaskInstantiation(BaseIntegrationTest):
codemod = FixTaskInstantiation
code_path = "tests/samples/fix_task_instantiation.py"
class TestFixAsyncTaskInstantiation(BaseIntegrationTest):
codemod = FixAsyncTaskInstantiation
code_path = "tests/samples/fix_async_task_instantiation.py"
original_code, expected_new_code = original_and_expected_from_code_path(
code_path,
[
Expand Down Expand Up @@ -35,5 +35,5 @@ class TestFixTaskInstantiation(BaseIntegrationTest):
# fmt: on

expected_line_change = "8"
change_description = FixTaskInstantiation.change_description
change_description = FixAsyncTaskInstantiation.change_description
num_changed_files = 1
2 changes: 1 addition & 1 deletion src/codemodder/scripts/generate_docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ class DocMetadata:
importance="Medium",
guidance_explained="We believe this change is safe and will not cause any issues.",
),
"fix-task-instantiation": DocMetadata(
"fix-async-task-instantiation": DocMetadata(
importance="Low",
guidance_explained="Manual instantiation of `asyncio.Task` is discouraged. We believe this change is safe and will not cause any issues.",
),
Expand Down
4 changes: 2 additions & 2 deletions src/core_codemods/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
from .sonar.sonar_flask_json_response_type import SonarFlaskJsonResponseType
from .sonar.sonar_django_json_response_type import SonarDjangoJsonResponseType
from .lazy_logging import LazyLogging
from .fix_task_instantiation import FixTaskInstantiation
from .fix_async_task_instantiation import FixAsyncTaskInstantiation

registry = CodemodCollection(
origin="pixee",
Expand Down Expand Up @@ -117,7 +117,7 @@
RemoveAssertionInPytestRaises,
FixAssertTuple,
LazyLogging,
FixTaskInstantiation,
FixAsyncTaskInstantiation,
],
)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
The `asyncio` [documentation](https://docs.python.org/3/library/asyncio-task.html#asyncio.Task) explicitly discourages manual instantiation of a `Task` instance and instead recommends calling `create_task`.
The `asyncio` [documentation](https://docs.python.org/3/library/asyncio-task.html#asyncio.Task) explicitly discourages manual instantiation of a `Task` instance and instead recommends calling `create_task`. This keeps your code in line with recommended best practices and promotes maintainability.

Our changes look like the following:
```diff
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@
from codemodder.codemods.utils import BaseType, infer_expression_type


class FixTaskInstantiation(SimpleCodemod, NameAndAncestorResolutionMixin):
class FixAsyncTaskInstantiation(SimpleCodemod, NameAndAncestorResolutionMixin):
metadata = Metadata(
name="fix-task-instantiation",
summary="Use high-level `asyncio.create_task` API",
review_guidance=ReviewGuidance.MERGE_WITHOUT_REVIEW,
name="fix-async-task-instantiation",
summary="Use High-Level `asyncio` API Functions to Create Tasks",
review_guidance=ReviewGuidance.MERGE_AFTER_CURSORY_REVIEW,
references=[
Reference(
url="https://docs.python.org/3/library/asyncio-task.html#asyncio.Task"
),
],
)
change_description = "Replace instantiation of `asyncio.Task` with `create_task`"
change_description = "Replace instantiation of `asyncio.Task` higher-level functions to create tasks."
_module_name = "asyncio"

def leave_Call(self, original_node: cst.Call, updated_node: cst.Call) -> cst.Call:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import pytest
from core_codemods.fix_task_instantiation import FixTaskInstantiation
from core_codemods.fix_async_task_instantiation import FixAsyncTaskInstantiation
from tests.codemods.base_codemod_test import BaseCodemodTest


class TestFixTaskInstantiation(BaseCodemodTest):
codemod = FixTaskInstantiation
class TestFixAsyncTaskInstantiation(BaseCodemodTest):
codemod = FixAsyncTaskInstantiation

@pytest.mark.parametrize(
"input_code,expected_output",
Expand Down
File renamed without changes.

0 comments on commit 5f2813b

Please sign in to comment.