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

DEV: Remove ignore Ruff rule RET503 #3209

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open

DEV: Remove ignore Ruff rule RET503 #3209

wants to merge 6 commits into from

Conversation

j-t-1
Copy link
Contributor

@j-t-1 j-t-1 commented Mar 21, 2025

RET503: Missing explicit "return" at the end of function able to return non-"None" value.

j-t-1 added 4 commits March 21, 2025 12:18
RET503: Missing explicit "return" at the end of function able to return non-"None" value.
RET503: Missing explicit "return" at the end of function able to return non-"None" value.
RET503: Missing explicit "return" at the end of function able to return non-"None" value.
RET503: Missing explicit "return" at the end of function able to return non-"None" value.
Copy link

codecov bot commented Mar 21, 2025

Codecov Report

Attention: Patch coverage is 66.66667% with 1 line in your changes missing coverage. Please review.

Project coverage is 96.52%. Comparing base (45a0885) to head (e1b86e3).
Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
pypdf/_writer.py 50.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3209      +/-   ##
==========================================
- Coverage   96.53%   96.52%   -0.02%     
==========================================
  Files          53       53              
  Lines        8930     8933       +3     
  Branches     1642     1642              
==========================================
+ Hits         8621     8623       +2     
- Misses        186      187       +1     
  Partials      123      123              

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

pypdf/_page.py Outdated
@@ -1248,6 +1248,7 @@ def _merge_page(
self.replace_contents(ContentStream(new_content_array, self.pdf))
self[NameObject(PG.RESOURCES)] = new_resources
self[NameObject(PG.ANNOTS)] = new_annots
return
Copy link
Collaborator

Choose a reason for hiding this comment

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

Does this not make sense as this method should always return None.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Without the return:

RET503 Missing explicit return at the end of function able to return non-None value.

I think you are right, that this function only returns None. I have added _page.py to [tool.ruff.lint.per-file-ignores].

Copy link
Collaborator

Choose a reason for hiding this comment

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

I disagree with this. We should never exclude a whole file from a rule if it is only relevant for one line. Apart from this, it seems like this might be a bug in the detection logic - this method will never return something different than None given its type hints and implementation.

@@ -2187,6 +2187,7 @@ def clean_forms(

clean(content, images, forms)
page.replace_contents(content)
return
Copy link
Collaborator

Choose a reason for hiding this comment

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

How is this a valid return value for the given type hints?

@@ -3105,6 +3106,7 @@ def find_outline_item(
o = cast(TreeObject, o["/Next"])
else:
return None
return
Copy link
Collaborator

Choose a reason for hiding this comment

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

There are two issues here:

  • We always return None - why does this check trigger at all?
  • If this is a valid case, we should have a test for it as well.

j-t-1 added 2 commits March 22, 2025 15:11
RET503: Missing explicit "return" at the end of function able to return non-"None" value.
RET503: Missing explicit "return" at the end of function able to return non-"None" value.
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.

2 participants