Skip to content

Comments

Add type-checking#410

Merged
deeplook merged 5 commits intomainfrom
pr/409
Sep 12, 2025
Merged

Add type-checking#410
deeplook merged 5 commits intomainfrom
pr/409

Conversation

@deeplook
Copy link
Owner

@deeplook deeplook commented Sep 12, 2025

Add static type checking.

self.shape_converter.applyTransformOnGroup(transform, group)

def xlink_href_target(self, node, group=None):
def xlink_href_target(self, node: NodeTracker, group: Optional[Any] = None) -> Any:

Check notice

Code scanning / CodeQL

Explicit returns mixed with implicit (fall through) returns Note

Mixing implicit and explicit returns may indicate an error, as implicit returns always return None.

Copilot Autofix

AI 5 months ago

To fix the explicit–implicit return mixing, add an explicit return None at the end of the xlink_href_target function. This does not change functionality, as the function would implicitly return None anyway if no return statements are hit, but improves code clarity.
Edit only the function xlink_href_target in src/svglib/svglib.py, adding return None before the function ends (after line 834 <end of function>). No external imports or definitions are needed.


Suggested changeset 1
src/svglib/svglib.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/src/svglib/svglib.py b/src/svglib/svglib.py
--- a/src/svglib/svglib.py
+++ b/src/svglib/svglib.py
@@ -831,6 +831,7 @@
                 # The missing definition should appear later in the file
                 self.waiting_use_nodes[fragment].append((node, group))
                 return DELAYED
+            return None
 
     def renderTitle_(self, node: NodeTracker) -> None:
         # Main SVG title attr. could be used in the PDF document info field.
EOF
@@ -831,6 +831,7 @@
# The missing definition should appear later in the file
self.waiting_use_nodes[fragment].append((node, group))
return DELAYED
return None

def renderTitle_(self, node: NodeTracker) -> None:
# Main SVG title attr. could be used in the PDF document info field.
Copilot is powered by AI and may make mistakes. Always verify output.
@deeplook deeplook committed this autofix suggestion 5 months ago.
Comment on lines +924 to +929
def renderUse(
self,
node: NodeTracker,
group: Optional[Any] = None,
clipping: Optional[Any] = None,
) -> Any:

Check notice

Code scanning / CodeQL

Explicit returns mixed with implicit (fall through) returns Note

Mixing implicit and explicit returns may indicate an error, as implicit returns always return None.

Copilot Autofix

AI 5 months ago

To fix the issue, add an explicit return None statement at the end of the renderUse method in src/svglib/svglib.py. This ensures that, if none of the previous if/elif/else branches are taken, the function's return value is explicitly specified. This change keeps the function's behaviour the same as before, but makes the intent clearer for maintainers. The only change required is to add the explicit return at the end of the method.

Suggested changeset 1
src/svglib/svglib.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/src/svglib/svglib.py b/src/svglib/svglib.py
--- a/src/svglib/svglib.py
+++ b/src/svglib/svglib.py
@@ -956,8 +956,8 @@
         self.renderNode(list(node.iter_children())[-1], parent=group)
         self.apply_node_attr_to_group(node, group)
         return group
+        return None
 
-
 class SvgShapeConverter:
     """An abstract SVG shape converter.
 
EOF
@@ -956,8 +956,8 @@
self.renderNode(list(node.iter_children())[-1], parent=group)
self.apply_node_attr_to_group(node, group)
return group
return None


class SvgShapeConverter:
"""An abstract SVG shape converter.

Copilot is powered by AI and may make mistakes. Always verify output.
@deeplook deeplook committed this autofix suggestion 5 months ago.
"""Converter from SVG shapes to RLG (ReportLab Graphics) shapes."""

def convertShape(self, name, node, clipping=None):
def convertShape(self, name: str, node: Any, clipping: Optional[Any] = None) -> Any:

Check notice

Code scanning / CodeQL

Explicit returns mixed with implicit (fall through) returns Note

Mixing implicit and explicit returns may indicate an error, as implicit returns always return None.

Copilot Autofix

AI 5 months ago

To fix the problem, explicitly return None instead of using a bare return statement where no value is intended. In this code, update the line return (line 997) to return None. This minor edit improves code readability and consistency, making it clear what value is returned in all branches. No other changes, imports, or definitions are required.


Suggested changeset 1
src/svglib/svglib.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/src/svglib/svglib.py b/src/svglib/svglib.py
--- a/src/svglib/svglib.py
+++ b/src/svglib/svglib.py
@@ -994,7 +994,7 @@
         method_name = f"convert{name.capitalize()}"
         shape = getattr(self, method_name)(node)
         if not shape:
-            return
+            return None
         if name not in ("path", "polyline", "text"):
             # Only apply style where the convert method did not apply it.
             self.applyStyleOnShape(shape, node)
EOF
@@ -994,7 +994,7 @@
method_name = f"convert{name.capitalize()}"
shape = getattr(self, method_name)(node)
if not shape:
return
return None
if name not in ("path", "polyline", "text"):
# Only apply style where the convert method did not apply it.
self.applyStyleOnShape(shape, node)
Copilot is powered by AI and may make mistakes. Always verify output.
deeplook and others added 2 commits September 12, 2025 19:11
…with implicit (fall through) returns

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
…with implicit (fall through) returns

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
# The missing definition should appear later in the file
self.waiting_use_nodes[fragment].append((node, group))
return DELAYED
return None

Check warning

Code scanning / CodeQL

Unreachable code Warning

This statement is unreachable.

Copilot Autofix

AI 5 months ago

The fix is straightforward: remove the unreachable return None statement on line 834 within the xlink_href_target method in src/svglib/svglib.py. This code is never executed given the preceding unconditional return DELAYED. No functional change will be introduced by this deletion, and code clarity will be improved. Only one line (834) in the file is to be removed; no imports, methods, or additional definitions are needed.

Suggested changeset 1
src/svglib/svglib.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/src/svglib/svglib.py b/src/svglib/svglib.py
--- a/src/svglib/svglib.py
+++ b/src/svglib/svglib.py
@@ -831,7 +831,6 @@
                 # The missing definition should appear later in the file
                 self.waiting_use_nodes[fragment].append((node, group))
                 return DELAYED
-            return None
 
     def renderTitle_(self, node: NodeTracker) -> None:
         # Main SVG title attr. could be used in the PDF document info field.
EOF
@@ -831,7 +831,6 @@
# The missing definition should appear later in the file
self.waiting_use_nodes[fragment].append((node, group))
return DELAYED
return None

def renderTitle_(self, node: NodeTracker) -> None:
# Main SVG title attr. could be used in the PDF document info field.
Copilot is powered by AI and may make mistakes. Always verify output.
deeplook and others added 2 commits September 12, 2025 19:16
…with implicit (fall through) returns

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
self.renderNode(list(node.iter_children())[-1], parent=group)
self.apply_node_attr_to_group(node, group)
return group
return None

Check warning

Code scanning / CodeQL

Unreachable code Warning

This statement is unreachable.

Copilot Autofix

AI 5 months ago

To fix this issue, we should delete the unreachable return None statement on line 959 of src/svglib/svglib.py. This statement appears directly after another return and cannot ever be executed. Removing it will clarify the code and avoid confusion. No other code changes, imports, or definitions are necessary, as the removal has no impact on existing functionality. The edit should only remove the single unreachable line, keeping all other content intact.


Suggested changeset 1
src/svglib/svglib.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/src/svglib/svglib.py b/src/svglib/svglib.py
--- a/src/svglib/svglib.py
+++ b/src/svglib/svglib.py
@@ -956,9 +956,9 @@
         self.renderNode(list(node.iter_children())[-1], parent=group)
         self.apply_node_attr_to_group(node, group)
         return group
-        return None
 
 
+
 class SvgShapeConverter:
     """An abstract SVG shape converter.
 
EOF
@@ -956,9 +956,9 @@
self.renderNode(list(node.iter_children())[-1], parent=group)
self.apply_node_attr_to_group(node, group)
return group
return None



class SvgShapeConverter:
"""An abstract SVG shape converter.

Copilot is powered by AI and may make mistakes. Always verify output.
@deeplook deeplook changed the title Pr/409 Add type-checking Sep 12, 2025
@deeplook deeplook merged commit 3237aa1 into main Sep 12, 2025
17 of 18 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.

1 participant