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

gh-78997: AttributeError if loading fails in LibraryLoader.__getattr__ #25177

Merged
merged 7 commits into from
Dec 15, 2022

Conversation

farfella
Copy link
Contributor

@farfella farfella commented Apr 4, 2021

@the-knights-who-say-ni
Copy link

Hello, and thanks for your contribution!

I'm a bot set up to make sure that the project can legally accept this contribution by verifying everyone involved has signed the PSF contributor agreement (CLA).

CLA Missing

Our records indicate the following people have not signed the CLA:

@farfella

For legal reasons we need all the people listed to sign the CLA before we can look at your contribution. Please follow the steps outlined in the CPython devguide to rectify this issue.

If you have recently signed the CLA, please wait at least one business day
before our records are updated.

You can check yourself to see if the CLA has been received.

Thanks again for the contribution, we look forward to reviewing it!

@github-actions
Copy link

This PR is stale because it has been open for 30 days with no activity.

@github-actions github-actions bot added the stale Stale PR or inactive for long period of time. label Jun 13, 2021
@jacobtylerwalls
Copy link
Contributor

jacobtylerwalls commented Jun 14, 2021

Hi @farfella, thanks for this, do you think you could add a brief test to verify the original use case? I'm not an expert, but I would assume Lib/ctypes/test/test_loader.py would be a reasonable place to start.

@jacobtylerwalls
Copy link
Contributor

Ah, sorry I was referring to an existing file and meant "test_loading.py", not "test_loader.py", my mistake:

class LoaderTest(unittest.TestCase):

@farfella
Copy link
Contributor Author

Thanks for your all your help and feedback, @jacobtylerwalls! :) Hoping style-checks passes this time.

@github-actions github-actions bot removed the stale Stale PR or inactive for long period of time. label Jun 15, 2021
@farfella
Copy link
Contributor Author

Thanks! Fewer lines of code. :)

@@ -0,0 +1 @@
Fix issue where hasattr(ctypes.windll, 'somefunction') raises OSError instead of the expected behavior: returning False
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
Fix issue where hasattr(ctypes.windll, 'somefunction') raises OSError instead of the expected behavior: returning False
`hasattr(ctypes.windll, 'nonexistant')` now returns `False` instead of raising `OSError`.

Comment on lines 122 to 124
# This test case verifies that
# ctypes.LoadLibrary.__getattr__ raises AttributeError
# when name cannot be resolved
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
# This test case verifies that
# ctypes.LoadLibrary.__getattr__ raises AttributeError
# when name cannot be resolved
# bpo-34816: shouldn't raise OSError

Copy link
Contributor

@eric-wieser eric-wieser left a comment

Choose a reason for hiding this comment

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

LGTM!

@netlify
Copy link

netlify bot commented Dec 15, 2022

Deploy Preview for python-cpython-preview canceled.

Name Link
🔨 Latest commit f151341
🔍 Latest deploy log https://app.netlify.com/sites/python-cpython-preview/deploys/639b9b8d57bbf700082c03c5

@FFY00
Copy link
Member

FFY00 commented Dec 15, 2022

@farfella I am now in a position where I can merge this, could you update the PR to resolve the conflicts?

@bedevere-bot
Copy link

Most changes to Python require a NEWS entry.

Please add it using the blurb_it web app or the blurb command-line tool.

@cpython-cla-bot
Copy link

cpython-cla-bot bot commented Dec 15, 2022

All commit authors signed the Contributor License Agreement.
CLA signed

@eric-wieser
Copy link
Contributor

@farfella, it looks like you just discarded all your changes...

@farfella
Copy link
Contributor Author

Yeah.... I saw this "Sync fork" button (that is new to me) for my branch on GitHub web UI and clicked it. This is the consequence.... My local copy still has everything. I'll push that up.

@farfella
Copy link
Contributor Author

Updated PR to resolve conflicts

@farfella farfella reopened this Dec 15, 2022
@cjw296 cjw296 removed their request for review December 15, 2022 20:13
@terryjreedy
Copy link
Member

force-pushing may be the reason for the review-request spamming. Please use simple update merges. git merge upstream/main last I knew.

@terryjreedy terryjreedy changed the title bpo-34816: Raise AttributeError if loading fails in ctypes.LibraryLoader.__get_attr__ gh-78997: Raise AttributeError if loading fails in ctypes.LibraryLoader.__get_attr__ Dec 15, 2022
@FFY00
Copy link
Member

FFY00 commented Dec 15, 2022

Alright, thank you @farfella for getting this back into shape! Can you just apply the feedback from code-review from @eric-wieser? After that, we can go ahead and merge this 👍

Co-authored-by: Zachary Ware <zachary.ware@gmail.com>
@AlexWaygood AlexWaygood changed the title gh-78997: Raise AttributeError if loading fails in ctypes.LibraryLoader.__get_attr__ gh-78997: Raise AttributeError if loading fails in ctypes.LibraryLoader.__getattr__ Dec 15, 2022
@FFY00 FFY00 changed the title gh-78997: Raise AttributeError if loading fails in ctypes.LibraryLoader.__getattr__ gh-78997: AttributeError if loading fails in LibraryLoader.__getattr__ Dec 15, 2022
@FFY00 FFY00 merged commit 101cfe6 into python:main Dec 15, 2022
@FFY00
Copy link
Member

FFY00 commented Dec 15, 2022

Thanks @farfella for the fix, and @eric-wieser for the review!

eli-schwartz added a commit to eli-schwartz/cpython that referenced this pull request Dec 22, 2022
During the process of merging in a year and a half of changes, the
modified test file `test_loading.py` accidentally got converted to a
newly added file in an old location, rather than an existing test file
with an updated test.

Merge the changes in this file into the new canonical location since
pythongh-93839, and delete the old file.
@eli-schwartz
Copy link
Contributor

Minor rebase issue in the test file. :)

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.

10 participants