Title: gh-103193: Improve `getattr_static` test coverage by AlexWaygood · Pull Request #104286 · python/cpython · GitHub
Open Graph Title: gh-103193: Improve `getattr_static` test coverage by AlexWaygood · Pull Request #104286 · python/cpython
X Title: gh-103193: Improve `getattr_static` test coverage by AlexWaygood · Pull Request #104286 · python/cpython
Description: Currently, no tests would fail if we were to apply this optimisation to getattr_static, which makes things a fair bit faster: --- a/Lib/inspect.py +++ b/Lib/inspect.py @@ -1780,13 +1780,9 @@ def trace(context=1): def _check_instance(obj, attr): - instance_dict = {} - try: - instance_dict = object.__getattribute__(obj, "__dict__") - except AttributeError: - pass - return dict.get(instance_dict, attr, _sentinel) - + if hasattr(obj, "__dict__"): + return dict.get(obj.__dict__, attr, _sentinel) + return _sentinel However, the optimisation would lead to incorrect behaviour. test_custom___getattribute__, added in this PR, would correctly fail if the incorrect optimisation were applied. Issue: gh-103193
Open Graph Description: Currently, no tests would fail if we were to apply this optimisation to getattr_static, which makes things a fair bit faster: --- a/Lib/inspect.py +++ b/Lib/inspect.py @@ -1780,13 +1780,9 @@ def tr...
X Description: Currently, no tests would fail if we were to apply this optimisation to getattr_static, which makes things a fair bit faster: --- a/Lib/inspect.py +++ b/Lib/inspect.py @@ -1780,13 +1780,9 @@ def tr...
Opengraph URL: https://github.com/python/cpython/pull/104286
X: @github
Domain: github.com
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:a9802710-d960-e9ea-cd9f-b8bcbf7b5192 |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | 9FD8:15A631:AAA38:E6BAF:6969CBB8 |
| html-safe-nonce | 89463062e6f496588fb4a0148be9d9a5555ec157adccd02c39b6dc6146b5894a |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5RkQ4OjE1QTYzMTpBQUEzODpFNkJBRjo2OTY5Q0JCOCIsInZpc2l0b3JfaWQiOiIxNTQ4NjQ1NjM2ODE2NjIwNDcyIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 84a10ee036e2278fbc24f09f0d18a8f56b4ed264f499c2e0a6932913839a6825 |
| hovercard-subject-tag | pull_request:1341797589 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/python/cpython/pull/104286/files |
| twitter:image | https://avatars.githubusercontent.com/u/66076021?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/66076021?s=400&v=4 |
| og:image:alt | Currently, no tests would fail if we were to apply this optimisation to getattr_static, which makes things a fair bit faster: --- a/Lib/inspect.py +++ b/Lib/inspect.py @@ -1780,13 +1780,9 @@ def tr... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | acedec8b5f975d9e3d494ddd8f949b0b8a0de59d393901e26f73df9dcba80056 |
| turbo-cache-control | no-preview |
| diff-view | unified |
| go-import | github.com/python/cpython git https://github.com/python/cpython.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 81598961 |
| octolytics-dimension-repository_nwo | python/cpython |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 81598961 |
| octolytics-dimension-repository_network_root_nwo | python/cpython |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | true |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 83c08c21cdda978090dc44364b71aa5bc6dcea79 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width