← 返回首页
gh-78997: AttributeError if loading fails in LibraryLoader.__getattr__ by farfella · Pull Request #25177 · python/cpython · GitHub
Skip to content

Navigation Menu

Toggle navigation
Sign in
Appearance settings
Search or jump to...

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Include my email address so I can be contacted

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Resetting focus

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

Merged
FFY00 merged 7 commits into
python:mainfrom
farfella:bpo-34816
Dec 15, 2022
Merged

gh-78997: AttributeError if loading fails in LibraryLoader.__getattr__#25177
FFY00 merged 7 commits into
python:mainfrom
farfella:bpo-34816

Conversation

farfella commented Apr 4, 2021
edited by terryjreedy
Loading

Copy link
Copy Markdown
Contributor

Copy link
Copy Markdown

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!

Copy link
Copy Markdown

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

github-actions Bot added the stale Stale PR or inactive for long period of time. label Jun 13, 2021

jacobtylerwalls commented Jun 14, 2021
edited
Loading

Copy link
Copy Markdown
Contributor

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.

Copy link
Copy Markdown
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):

Copy link
Copy Markdown
Contributor Author

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

Comment thread Lib/ctypes/test/test_loading.py Outdated Show resolved Hide resolved
github-actions Bot removed the stale Stale PR or inactive for long period of time. label Jun 15, 2021

Copy link
Copy Markdown
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 No newline at end of file

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality Hide comment
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 thread Lib/ctypes/test/test_loading.py Outdated
Comment on lines +122 to +124
# This test case verifies that
# ctypes.LoadLibrary.__getattr__ raises AttributeError
# when name cannot be resolved

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality Hide comment
Suggested change
# This test case verifies that
# ctypes.LoadLibrary.__getattr__ raises AttributeError
# when name cannot be resolved
# bpo-34816: shouldn't raise OSError

eric-wieser left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality Hide comment

LGTM!

netlify Bot commented Dec 15, 2022
edited
Loading

Copy link
Copy Markdown

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 commented Dec 15, 2022

Copy link
Copy Markdown
Member

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

58 hidden items Load more…

Copy link
Copy Markdown

Most changes to Python require a NEWS entry.

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

ghost commented Dec 15, 2022
edited by ghost
Loading

Copy link
Copy Markdown

All commit authors signed the Contributor License Agreement.

Copy link
Copy Markdown
Contributor

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

Copy link
Copy Markdown
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.

Copy link
Copy Markdown
Contributor Author

Updated PR to resolve conflicts

farfella reopened this Dec 15, 2022

Copy link
Copy Markdown
Member

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

FFY00 commented Dec 15, 2022

Copy link
Copy Markdown
Member

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 👍

Comment thread Misc/NEWS.d/next/Windows/2021-04-08-00-36-37.bpo-34816.4Xe0id.rst Outdated Show resolved Hide resolved
Comment thread Misc/NEWS.d/next/Windows/2021-04-08-00-36-37.bpo-34816.4Xe0id.rst Outdated Show resolved Hide resolved
Comment thread Misc/NEWS.d/next/Windows/2021-04-08-00-36-37.bpo-34816.4Xe0id.rst Outdated Show resolved Hide resolved
Co-authored-by: Zachary Ware <zachary.ware@gmail.com>

FFY00 commented Dec 15, 2022

Copy link
Copy Markdown
Member

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

Copy link
Copy Markdown
Contributor

Minor rebase issue in the test file. :)

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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

Footer

© 2026 GitHub, Inc.