Title: Extract all "import gc" to module level by EliahKagan · Pull Request #1765 · gitpython-developers/GitPython · GitHub
Open Graph Title: Extract all "import gc" to module level by EliahKagan · Pull Request #1765 · gitpython-developers/GitPython
X Title: Extract all "import gc" to module level by EliahKagan · Pull Request #1765 · gitpython-developers/GitPython
Description: The gc module was already imported at module scope in git/repo/base.py. Although it was moved recently, it is not a new addition. It has been present for about seven years, since f1a82e4 (#555). Importing the top-level git module or any submodule of it runs that import statement: >>> import sys >>> "gc" in sys.modules False >>> import git >>> "gc" in sys.modules True Because the gc module is already imported, reimporting it is fast. Imports that there is no specific reason to do locally should be at module scope. Having them local decreased readability, in part because of how black inserts a black line between them and gc.collect() calls they are imported to allow. An alternative to this change would be to remove the preexisting top-level import gc (there is also another one in the test suite) and replace it with a local import as well. I am unsure if that would affect performance and, if so, whether the effect would be good or bad, since the small delay of the import might potentially be less desirable to an application if it occurs while the work of the application is already in progress. If a gc.collect() call runs as a consequence of a finally block or __del__ method being called during interpreter shutdown, then in (very) rare cases the variable may have been set to None. But this does not appear to have been the intent behind making the imports local. More importantly, a local import should not be expected to succeed, or the imported module usable, in such a situation. Conceptually unrelated to this, it looks like the newly released version of black fails to install on Cygwin in the test-cygwin.yml workflow. I expect failures from that workflow for this reason. Although unrelated, there is of course no rush on this PR, and if that does happen, it would prevent any Cygwin tests from running until a fix or workaround is applied. If that is fixed first, this PR could be rebased. If this problem doesn't happen, then it is resolved or somehow specific to the setup in my fork and on my local machine, in which case probably nothing has to be done about it.
Open Graph Description: The gc module was already imported at module scope in git/repo/base.py. Although it was moved recently, it is not a new addition. It has been present for about seven years, since f1a82e4 (#555). Im...
X Description: The gc module was already imported at module scope in git/repo/base.py. Although it was moved recently, it is not a new addition. It has been present for about seven years, since f1a82e4 (#555). Im...
Opengraph URL: https://github.com/gitpython-developers/GitPython/pull/1765
X: @github
Domain: github.com
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:f104a2b0-9cb9-12e8-3607-034d459f1f45 |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | DA7C:D2872:8721:B0FB:6968AF84 |
| html-safe-nonce | 8ec161994d144077bf5e06aa9713839d265d3183dcf54d6c3218cddcc59d65d2 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEQTdDOkQyODcyOjg3MjE6QjBGQjo2OTY4QUY4NCIsInZpc2l0b3JfaWQiOiIxNDI0MTEzMzY1MDExNzA1NzMyIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 1d4aa770b251fb0efeae465bbd0da58827d09239cf7335ed8a434a67de8f7c76 |
| hovercard-subject-tag | pull_request:1640581401 |
| 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/gitpython-developers/GitPython/pull/1765/files |
| twitter:image | https://avatars.githubusercontent.com/u/1771172?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/1771172?s=400&v=4 |
| og:image:alt | The gc module was already imported at module scope in git/repo/base.py. Although it was moved recently, it is not a new addition. It has been present for about seven years, since f1a82e4 (#555). Im... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | fdc7c66bd36a6c12eb8e771e806db863266e573fc299e77f27505a768d4f8a98 |
| turbo-cache-control | no-preview |
| diff-view | unified |
| go-import | github.com/gitpython-developers/GitPython git https://github.com/gitpython-developers/GitPython.git |
| octolytics-dimension-user_id | 503709 |
| octolytics-dimension-user_login | gitpython-developers |
| octolytics-dimension-repository_id | 1126087 |
| octolytics-dimension-repository_nwo | gitpython-developers/GitPython |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 1126087 |
| octolytics-dimension-repository_network_root_nwo | gitpython-developers/GitPython |
| turbo-body-classes | logged-out env-production page-responsive full-width |
| disable-turbo | true |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 3223a6503d318917691422cdadfbe16cd8fb21e5 |
| ui-target | canary-2 |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width