Skip to content

Conversation

vinitkumar
Copy link
Owner

@vinitkumar vinitkumar commented Aug 29, 2025

Summary by Sourcery

Clean up test code and lint configuration by removing redundant type imports in TYPE_CHECKING blocks and re-enabling unused import detection.

Enhancements:

  • Simplify TYPE_CHECKING blocks in test files by replacing imported type definitions with a pass statement to reduce boilerplate.

Build:

  • Remove ‘F401’ (unused import) from lint.ignore in pyproject.toml to enforce unused import detection.

@vinitkumar vinitkumar requested a review from Copilot August 29, 2025 10:30
Copy link
Contributor

sourcery-ai bot commented Aug 29, 2025

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

This PR removes redundant type-only imports from test modules and tightens linting rules by re-enabling unused-import checks.

File-Level Changes

Change Details Files
Clean up TYPE_CHECKING blocks in test files
  • Removed multiple pytest and pytest-mock type imports
  • Replaced imports with a pass statement in TYPE_CHECKING
tests/test_dict2xml.py
tests/test_utils.py
Re-enable unused-import linting
  • Removed 'F401' from lint.ignore in pyproject.toml
pyproject.toml

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copilot

This comment was marked as outdated.

Copy link

codecov bot commented Aug 29, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (5f226ca) to head (d737811).

Additional details and impacted files
@@             Coverage Diff             @@
##           master      #248      +/-   ##
===========================================
+ Coverage   99.30%   100.00%   +0.69%     
===========================================
  Files           3         3              
  Lines         288       288              
===========================================
+ Hits          286       288       +2     
+ Misses          2         0       -2     
Flag Coverage Δ
unittests 100.00% <100.00%> (+0.69%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey there - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment on lines 7 to 9

if TYPE_CHECKING:
from _pytest.capture import CaptureFixture
from _pytest.fixtures import FixtureRequest
from _pytest.logging import LogCaptureFixture
from _pytest.monkeypatch import MonkeyPatch
from pytest_mock.plugin import MockerFixture
pass
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion (code-quality): Remove redundant conditional (remove-redundant-if)

Suggested change
if TYPE_CHECKING:
from _pytest.capture import CaptureFixture
from _pytest.fixtures import FixtureRequest
from _pytest.logging import LogCaptureFixture
from _pytest.monkeypatch import MonkeyPatch
from pytest_mock.plugin import MockerFixture
pass

Comment on lines 19 to 20
if TYPE_CHECKING:
from _pytest.capture import CaptureFixture
from _pytest.fixtures import FixtureRequest
from _pytest.logging import LogCaptureFixture
from _pytest.monkeypatch import MonkeyPatch
from pytest_mock.plugin import MockerFixture
pass
Copy link
Contributor

Choose a reason for hiding this comment

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

issue (code-quality): Remove redundant conditional (remove-redundant-if)

@vinitkumar vinitkumar requested a review from Copilot August 29, 2025 10:58
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR cleans up test code and improves code quality by simplifying TYPE_CHECKING blocks and enforcing unused import detection. It removes redundant type imports that were only used for type checking and enables stricter linting.

  • Simplifies TYPE_CHECKING blocks by replacing type imports with pass statements
  • Removes actual unused imports from test files
  • Enables F401 linting rule to catch unused imports in the future

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
tests/test_utils.py Replaces TYPE_CHECKING imports with pass statement
tests/test_json2xml.py Removes unused json import
tests/test_dict2xml.py Removes unused numbers import and replaces TYPE_CHECKING imports with pass
pyproject.toml Removes F401 from ignored lint rules to enforce unused import detection

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment on lines 19 to 20
if TYPE_CHECKING:
from _pytest.capture import CaptureFixture
from _pytest.fixtures import FixtureRequest
from _pytest.logging import LogCaptureFixture
from _pytest.monkeypatch import MonkeyPatch
from pytest_mock.plugin import MockerFixture
pass
Copy link
Preview

Copilot AI Aug 29, 2025

Choose a reason for hiding this comment

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

Empty TYPE_CHECKING blocks with only 'pass' serve no purpose and add unnecessary code. Consider removing the entire TYPE_CHECKING block if no type imports are needed.

Copilot uses AI. Check for mistakes.

Comment on lines 8 to 9
if TYPE_CHECKING:
from _pytest.capture import CaptureFixture
from _pytest.fixtures import FixtureRequest
from _pytest.logging import LogCaptureFixture
from _pytest.monkeypatch import MonkeyPatch
from pytest_mock.plugin import MockerFixture
pass
Copy link
Preview

Copilot AI Aug 29, 2025

Choose a reason for hiding this comment

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

Empty TYPE_CHECKING blocks with only 'pass' serve no purpose and add unnecessary code. Consider removing the entire TYPE_CHECKING block if no type imports are needed.

Copilot uses AI. Check for mistakes.


def test_get_unique_id_collision_coverage(self) -> None:
"""Test get_unique_id to cover line 50 - the collision case."""
import json2xml.dicttoxml as module

Check notice

Code scanning / CodeQL

Module is imported with 'import' and 'import from' Note test

Module 'json2xml.dicttoxml' is imported with both 'import' and 'import from'.

Copilot Autofix

AI 16 days ago

The recommended fix is to remove the from json2xml import dicttoxml import (line 6) from the file and instead use a plain module import (import json2xml.dicttoxml) at the top level. Any use of dicttoxml throughout the test class will then need to be updated to reference json2xml.dicttoxml. This ensures there is only one import style for the module, as recommended. To preserve existing functionality, replace any call or reference to dicttoxml (as a module) with json2xml.dicttoxml (or another suitable alias if desired, but the most consistent choice is the fully-qualified name). Note that in this file, all the uses of dicttoxml.funcname and dicttoxml.dicttoxml, etc., will need to be adjusted accordingly.

All changes are limited to tests/test_dict2xml.py, affecting:

  • The import statements at the top of the file,
  • All instances where dicttoxml module is referenced (e.g., dicttoxml.dicttoxml, dicttoxml.get_unique_id, etc.).

No new imports are needed except the top-level import json2xml.dicttoxml. No changes to functionality are required outside changing the way the module is referenced.

Suggested changeset 1
tests/test_dict2xml.py

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/tests/test_dict2xml.py b/tests/test_dict2xml.py
--- a/tests/test_dict2xml.py
+++ b/tests/test_dict2xml.py
@@ -3,7 +3,7 @@
 
 import pytest
 
-from json2xml import dicttoxml
+import json2xml.dicttoxml
 
 
 class TestDict2xml:
@@ -1122,7 +1122,7 @@
     def test_attrs_empty_and_none_values(self) -> None:
         """Test attribute handling with empty and None values."""
         data = {"Element": {"@attrs": {"empty": "", "zero": 0, "false": False}}}
-        result = dicttoxml.dicttoxml(
+        result = json2xml.dicttoxml.dicttoxml(
             data, attr_type=False, item_wrap=False, root=False
         ).decode("utf-8")
 
@@ -1177,14 +1177,14 @@
 
         try:
             # First call - adds "test_123456" to _used_ids
-            result1 = dicttoxml.get_unique_id("test")
+            result1 = json2xml.dicttoxml.get_unique_id("test")
             assert result1 == "test_123456"
 
             # Reset call count for second test
             call_count = 0
 
             # Second call - should trigger collision and regenerate
-            result2 = dicttoxml.get_unique_id("test")
+            result2 = json2xml.dicttoxml.get_unique_id("test")
             assert result2 == "test_789012"
             assert call_count == 3  # Should have called make_id 3 times
         finally:
EOF
@@ -3,7 +3,7 @@

import pytest

from json2xml import dicttoxml
import json2xml.dicttoxml


class TestDict2xml:
@@ -1122,7 +1122,7 @@
def test_attrs_empty_and_none_values(self) -> None:
"""Test attribute handling with empty and None values."""
data = {"Element": {"@attrs": {"empty": "", "zero": 0, "false": False}}}
result = dicttoxml.dicttoxml(
result = json2xml.dicttoxml.dicttoxml(
data, attr_type=False, item_wrap=False, root=False
).decode("utf-8")

@@ -1177,14 +1177,14 @@

try:
# First call - adds "test_123456" to _used_ids
result1 = dicttoxml.get_unique_id("test")
result1 = json2xml.dicttoxml.get_unique_id("test")
assert result1 == "test_123456"

# Reset call count for second test
call_count = 0

# Second call - should trigger collision and regenerate
result2 = dicttoxml.get_unique_id("test")
result2 = json2xml.dicttoxml.get_unique_id("test")
assert result2 == "test_789012"
assert call_count == 3 # Should have called make_id 3 times
finally:
Copilot is powered by AI and may make mistakes. Always verify output.
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.

1 participant