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

Add with ... as ... usage #1117

Closed
wants to merge 34 commits into from
Closed

Add with ... as ... usage #1117

wants to merge 34 commits into from

Conversation

JianzhengLuo
Copy link
Contributor

Check the code, please?
By the way, would you like to add me into the Contributors of this project?

PyPDF2/_merger.py Outdated Show resolved Hide resolved
PyPDF2/_merger.py Show resolved Hide resolved
PyPDF2/_merger.py Outdated Show resolved Hide resolved
PyPDF2/_merger.py Show resolved Hide resolved
PyPDF2/_writer.py Outdated Show resolved Hide resolved
PyPDF2/_writer.py Outdated Show resolved Hide resolved
PyPDF2/_writer.py Outdated Show resolved Hide resolved
@JianzhengLuo
Copy link
Contributor Author

Already modified according to @MasterOdin requested changes, but why can't this request merge?

Copy link
Member

@MasterOdin MasterOdin left a comment

Choose a reason for hiding this comment

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

If you click "Details" for any of the failed test runs, you will see the error that's happening:

PyPDF2/_writer.py:169: error: Function is missing a type annotation  [no-untyped-def]
PyPDF2/_writer.py:173: error: Function is missing a return type annotation  [no-untyped-def]
PyPDF2/_writer.py:821: error: Argument 1 to "write_stream" of "PdfWriter" has incompatible type "Union[str, BytesIO, BufferedReader, BufferedWriter, FileIO]"; expected "Union[BytesIO, BufferedReader, BufferedWriter, FileIO]"  [arg-type]
PyPDF2/_writer.py:824: error: Item "str" of "Union[str, BytesIO, BufferedReader, BufferedWriter, FileIO]" has no attribute "close"  [union-attr]
PyPDF2/_merger.py:101: error: Function is missing a return type annotation  [no-untyped-def]

PyPDF2/_writer.py Outdated Show resolved Hide resolved
PyPDF2/_writer.py Outdated Show resolved Hide resolved
PyPDF2/_writer.py Outdated Show resolved Hide resolved
PyPDF2/_writer.py Outdated Show resolved Hide resolved
PyPDF2/_merger.py Outdated Show resolved Hide resolved
@MartinThoma
Copy link
Member

By the way, would you like to add me into the Contributors of this project?

We currently don't have a dedicated contributors page / document. I was thinking about adding it though :-) #798

@MartinThoma
Copy link
Member

Already modified according to @MasterOdin requested changes, but why can't this request merge?

Currently several tests fail because they are missing type annotations:

PyPDF2/_writer.py:169: error: Function is missing a type annotation  [no-untyped-def]
PyPDF2/_writer.py:173: error: Function is missing a return type annotation  [no-untyped-def]
PyPDF2/_writer.py:821: error: Argument 1 to "write_stream" of "PdfWriter" has incompatible type "Union[str, BytesIO, BufferedReader, BufferedWriter, FileIO]"; expected "Union[BytesIO, BufferedReader, BufferedWriter, FileIO]"  [arg-type]
PyPDF2/_writer.py:824: error: Item "str" of "Union[str, BytesIO, BufferedReader, BufferedWriter, FileIO]" has no attribute "close"  [union-attr]
PyPDF2/_merger.py:101: error: Function is missing a return type annotation  [no-untyped-def]

@MasterOdin has already added change requests that would fix those. You just need to merge them :-)

@codecov
Copy link

codecov bot commented Jul 18, 2022

Codecov Report

Merging #1117 (336053a) into main (0a6676f) will decrease coverage by 0.27%.
The diff coverage is 75.00%.

❗ Current head 336053a differs from pull request most recent head 092f209. Consider uploading reports for the commit 092f209 to get more accurate results

@@            Coverage Diff             @@
##             main    #1117      +/-   ##
==========================================
- Coverage   92.10%   91.82%   -0.28%     
==========================================
  Files          24       24              
  Lines        4913     4699     -214     
  Branches     1017      968      -49     
==========================================
- Hits         4525     4315     -210     
+ Misses        244      237       -7     
- Partials      144      147       +3     
Impacted Files Coverage Δ
PyPDF2/_merger.py 91.32% <66.66%> (-2.78%) ⬇️
PyPDF2/_writer.py 88.34% <78.94%> (+0.17%) ⬆️
PyPDF2/filters.py 92.52% <0.00%> (-2.81%) ⬇️
PyPDF2/_encryption.py 85.08% <0.00%> (-0.91%) ⬇️
PyPDF2/_cmap.py 93.81% <0.00%> (-0.45%) ⬇️
PyPDF2/_page.py 92.60% <0.00%> (-0.02%) ⬇️
PyPDF2/xmp.py 89.16% <0.00%> (ø)
PyPDF2/types.py 100.00% <0.00%> (ø)
PyPDF2/constants.py 100.00% <0.00%> (ø)
... and 4 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 0a6676f...092f209. Read the comment docs.

@JianzhengLuo
Copy link
Contributor Author

What's the problem again?
75.00% of diff hit (target 91.97%)?

@JianzhengLuo
Copy link
Contributor Author

@MartinThoma @MasterOdin Are you busy these days? I requested a review two days ago, but I didn't get a response till now, what happened?

@MartinThoma
Copy link
Member

@JianzhengLuo Please be patient - we probably all have full-time jobs and other things going on in our lives. For me, I say that there is currently a heat wave in Germany which means my appartment is at 32°C and more all the time - that makes pretty much anything where I need to think really hard.

PyPDF2/_writer.py Outdated Show resolved Hide resolved
Copy link
Member

@MartinThoma MartinThoma left a comment

Choose a reason for hiding this comment

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

Could you please add a unit test? If you need help with that, just let me know :-)

@JianzhengLuo
Copy link
Contributor Author

@JianzhengLuo Please be patient - we probably all have full-time jobs and other things going on in our lives. For me, I say that there is currently a heat wave in Germany which means my appartment is at 32°C and more all the time - that makes pretty much anything where I need to think really hard.

I'm sorry for making you angry, I knew that clearly - it's a volunteer job. You know, language is interesting, I just wanted to see what can I do for you, since adults are much busier than children. But when you read this, you might feel angry that I was not patiently and not considerate of you. Maybe next time I can add a emoji so the atmosphere will be more relaxing.

@JianzhengLuo
Copy link
Contributor Author

Hmm... The problems caused by pytest still exist. What can I do?

@JianzhengLuo
Copy link
Contributor Author

JianzhengLuo commented Jul 21, 2022

Some test_encryption errors also raised on my computer, but I didn't change anything about it. That's wired, could you help me find out what caused this, please? @MartinThoma

@MartinThoma
Copy link
Member

The encryption issue is weird, but let's first focus on the problem where I know how to fix it:

  1. Please restore test_merge
  2. Please crate a merger_operate as below:

This one should fix several issues:

def merger_operate(merger):
    pdf_path = os.path.join(RESOURCE_ROOT, "crazyones.pdf")
    outline = os.path.join(RESOURCE_ROOT, "pdflatex-outline.pdf")

    merger.append(pdf_path)
    merger.append(outline)

PyPDF2/_writer.py Outdated Show resolved Hide resolved
PyPDF2/_writer.py Outdated Show resolved Hide resolved
@JianzhengLuo
Copy link
Contributor Author

JianzhengLuo commented Jul 22, 2022

The encryption issue is weird, but let's first focus on the problem where I know how to fix it:

  1. Please restore test_merge
  2. Please crate a merger_operate as below:

This one should fix several issues:

def merger_operate(merger):
    pdf_path = os.path.join(RESOURCE_ROOT, "crazyones.pdf")
    outline = os.path.join(RESOURCE_ROOT, "pdflatex-outline.pdf")

    merger.append(pdf_path)
    merger.append(outline)

In that way, how could we test the other features in the original code? Do you mean we do this first to see where the problem is?

After I did what you said, and removed the uncorrelated test files such as test_encryption.py, I got the result below:

FAILED tests/test_merger.py::test_trim_outline_list - PyPDF2.errors.PdfReadError: Cannot read an empty file
FAILED tests/test_merger.py::test_sweep_recursion2[https://corpora.tika.apache.org/base/docs/govdocs1/924/924794.pdf-tika-924794.pdf] - PyPDF2.errors.PdfReadError: Cannot read an empty file
FAILED tests/test_writer.py::test_encrypt[True] - SystemError: more argument specifiers than keyword list entries (remaining format:'s#')
FAILED tests/test_writer.py::test_encrypt[False] - SystemError: more argument specifiers than keyword list entries (remaining format:'s#')

And then? @MartinThoma

By the way, why can't I re-request review to you?

PyPDF2/_merger.py Outdated Show resolved Hide resolved
@JianzhengLuo JianzhengLuo requested review from MasterOdin and MartinThoma and removed request for MartinThoma July 23, 2022 07:07
Copy link
Member

@MartinThoma MartinThoma left a comment

Choose a reason for hiding this comment

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

Could you please take care of those issues?

./PyPDF2/_writer.py:820:12: F821 undefined name 'fileobj'
./PyPDF2/_writer.py:821:48: F821 undefined name 'fileobj'
./PyPDF2/_writer.py:823:23: F821 undefined name 'fileobj'
./PyPDF2/_writer.py:824:30: F821 undefined name 'fileobj'

@JianzhengLuo
Copy link
Contributor Author

Could you please take care of those issues?

./PyPDF2/_writer.py:820:12: F821 undefined name 'fileobj'
./PyPDF2/_writer.py:821:48: F821 undefined name 'fileobj'
./PyPDF2/_writer.py:823:23: F821 undefined name 'fileobj'
./PyPDF2/_writer.py:824:30: F821 undefined name 'fileobj'

Very, very sorry for that! That wasn't an error before the commit a7346ef. I will fix that immediately.

@MartinThoma
Copy link
Member

No problem - don't worry :-)

@MartinThoma
Copy link
Member

I'm happy that you're working on this improvement - there isn't much missing to finish it.

I realize that it becomes frustrating when the PR is not merged for so long. If you want, I can finish it. Just let me know :-)

@JianzhengLuo
Copy link
Contributor Author

I'm happy that you're working on this improvement - there isn't much missing to finish it.

I realize that it becomes frustrating when the PR is not merged for so long. If you want, I can finish it. Just let me know :-)

It seems that I am annoying you, sorry for that! As the errors are too wired, since I didn't even change anything, than finish it if you like! Thank you.

@MartinThoma
Copy link
Member

It seems that I am annoying you, sorry for that!

No - everything is good 🤗 Don't worry :-)

@MartinThoma MartinThoma changed the title Add with ... as ... usage (#1108) Add with ... as ... usage Aug 1, 2022
@MartinThoma
Copy link
Member

@JianzhengLuo Your PR (now #1193 ) will be merged this week :-) Thank you for all the effort you put into it 🤗

I've added you to the CONTRIBUTORS.md file - if you want another text / a link to some profile, just let me know

MartinThoma added a commit that referenced this pull request Aug 3, 2022
Closes #1108
Closes #1117

Full credit for this PR goes to JianzhengLuo

Co-authored-by: JianzhengLuo <[email protected]>
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.

3 participants