René's URL Explorer Experiment


Title: Use zero-argument super() by EliahKagan · Pull Request #1726 · gitpython-developers/GitPython · GitHub

Open Graph Title: Use zero-argument super() by EliahKagan · Pull Request #1726 · gitpython-developers/GitPython

X Title: Use zero-argument super() by EliahKagan · Pull Request #1726 · gitpython-developers/GitPython

Description: This replaces 2-argument super(...) calls with the zero-argument super() form everywhere applicable: All uses of two-argument super in the code are replaced. All but one mention of two-argument super in comments are replaced. I had omitted this from #1725 because it may require more technical attention to fully check than other code changes there, and that PR was mostly for comments and docstrings. Exactly when super() can be used Since super is in practice one of the most confusing features of Python, I've included this section to help in verifying the changes here, and also so that they could be reverified later. However, this section is optional. As noted in output of help(super) (which is from this code, though the other documentation can be useful): super() -> same as super(__class__, ) __class__ is actually literal there--though the static __class__ cell should not be confused with the dynamic __class__ attribute--but it can also be thought of as standing for the name of the enclosing class (or narrowest enclosing class in the case of nested classes), which is actually what one typically writes in the two-argument form of super. When the expression passed in place of __class__ refers to the (narrowest enclosing) class, and the expression passed in place of is the name of the first parameter of the method (typically self in instance methods, or cls in class methods or __new__), the zero-argument form super() can be used instead with the same meaning. The one place I couldn't replace it The above-described situation applied everywhere in GitPython where super was actually used. However, there are also comments in some places describing how something else could be done or how what was done could be done differently. In those, most showings of multiple-argument super were replaceable with super without changing what the code would mean and do if used in the place the comment pertained to. But then there is this, in git.objects.util.TraversableIterableObj: GitPython/git/objects/util.py Lines 625 to 658 in 6cef9c0 def traverse( self: T_TIobj, predicate: Callable[[Union[T_TIobj, TIobj_tuple], int], bool] = lambda i, d: True, prune: Callable[[Union[T_TIobj, TIobj_tuple], int], bool] = lambda i, d: False, depth: int = -1, branch_first: bool = True, visit_once: bool = True, ignore_self: int = 1, as_edge: bool = False, ) -> Union[Iterator[T_TIobj], Iterator[Tuple[T_TIobj, T_TIobj]], Iterator[TIobj_tuple]]: """For documentation, see util.Traversable._traverse()""" """ # To typecheck instead of using cast. import itertools from git.types import TypeGuard def is_commit_traversed(inp: Tuple) -> TypeGuard[Tuple[Iterator[Tuple['Commit', 'Commit']]]]: for x in inp[1]: if not isinstance(x, tuple) and len(x) != 2: if all(isinstance(inner, Commit) for inner in x): continue return True ret = super(Commit, self).traverse(predicate, prune, depth, branch_first, visit_once, ignore_self, as_edge) ret_tup = itertools.tee(ret, 2) assert is_commit_traversed(ret_tup), f"{[type(x) for x in list(ret_tup[0])]}" return ret_tup[0] """ return cast( Union[Iterator[T_TIobj], Iterator[Tuple[Union[None, T_TIobj], T_TIobj]]], super(TraversableIterableObj, self)._traverse( predicate, prune, depth, branch_first, visit_once, ignore_self, as_edge # type: ignore ), ) The actual super call in the code there is replaceable, and I replaced it, with zero-argument super(). But the comment--or, more precisely, the string being used as a comment--shows a call with Commit as the class name. I'm not sure if that's intended or not. If it is intended, maybe it represents code that would be written somewhere else. So I haven't changed that, though I'm willing to do so if the matter is clarified. It could be changed either in a new commit in this PR, or in a subsequent PR. Other changes There's some proofreading of the kind done in #1725 that I missed there and took care of here. More significantly, TestBigRepoR.setUp contains: GitPython/test/performance/lib.py Lines 35 to 38 in 6cef9c0 try: super(TestBigRepoR, self).setUp() except AttributeError: pass And TestBigRepoRW.setUp analogously contains: GitPython/test/performance/lib.py Lines 67 to 70 in 6cef9c0 try: super(TestBigRepoRW, self).setUp() except AttributeError: pass In addition to replacing those two-argument super calls with zero-argument super(), I also removed the logic to catch and swallow AttributeError. As covered in more detail in the 9113177 commit message, this is unnecessary because unittest.TestCase defines an empty setUp method to allow this kind of special casing to be avoided, and it may be brittle because AttributeError could be raised from the actual code of a setUp method, due to the specific way the code to swallow it is written. However, if that latter effect, which would usually be strongly unwanted, is actually the goal, then this should be undone and a suitable comment and/or clarifying refactoring done. What isn't included It's unclear whether super calls in test classes' setUp and tearDown methods are always made in the places they are made because that is where superclass and sibling-class fixture acquisition and release behavior should occur. For example, usually, if setUp delegates via super to another class's setUp method at the beginning, and in a case where the corresponding tearDown method needs delegate via super to another class's tearDown method, then that tearDown call should be at the end, so that resource acquisition and release more often occurs in a temporally nested way that is easier to reason about and more often correct. However, sometimes doing it differently is deliberate. Furthermore, setUp and tearDown methods are inherently weird, because, if a subclass's setUp calls a superclass's setUp and then fails with an exception, then tearDown won't run. (Also, in situations where tearDown does run, an exception in one tearDown method may still prevent other MRO classes' tearDown methods from running. Unlike the first issue, for this there isn't really any perfect thing to do. But I think the framework still makes it somewhat harder than necessary to reason about when the tearDown calls are manually written rather than arranged and implied by the setUp logic.) For this reason, I am unsure if it is really worthwhile to try to improve ordering. If improvements are to be made, it might be best to have only setUp methods and have them register cleanup logic by calling addCleanup--or, perhaps better where applicable, enterContext, though a backport of it for Python <3.11 would be needed. Unlike tearDown methods, cleanup scheduled with addCleanup, either directly or through enterContext, is deterministically performed, in the opposite of the order it was added, even if setUp failed with an exception after the addCleanup call.

Open Graph Description: This replaces 2-argument super(...) calls with the zero-argument super() form everywhere applicable: All uses of two-argument super in the code are replaced. All but one mention of two-argument su...

X Description: This replaces 2-argument super(...) calls with the zero-argument super() form everywhere applicable: All uses of two-argument super in the code are replaced. All but one mention of two-argument su...

Opengraph URL: https://github.com/gitpython-developers/GitPython/pull/1726

X: @github

direct link

Domain: github.com

route-pattern/:user_id/:repository/pull/:id/checks(.:format)
route-controllerpull_requests
route-actionchecks
fetch-noncev2:cbcee917-2ffa-4adf-89db-f4d4022e3cb4
current-catalog-service-hash87dc3bc62d9b466312751bfd5f889726f4f1337bdff4e8be7da7c93d6c00a25a
request-idA782:96E3C:CDF9E9:124D6DA:696907E7
html-safe-nonce3e479aa47324892848c19336e439b42fa90ada3b227bc77900a8db32f5b9441a
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBNzgyOjk2RTNDOkNERjlFOToxMjRENkRBOjY5NjkwN0U3IiwidmlzaXRvcl9pZCI6IjgzMjkzMDAyMjQzMDcxNjkyNTUiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ==
visitor-hmac820f7abce15bdb649d6a8108c7f6f4c03272d731387d9e6a5ac6b0f5e9b92143
hovercard-subject-tagpull_request:1584866435
github-keyboard-shortcutsrepository,pull-request-list,pull-request-conversation,pull-request-files-changed,checks,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///pull_requests/show/checks
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/gitpython-developers/GitPython/pull/1726/checks
twitter:imagehttps://avatars.githubusercontent.com/u/1771172?s=400&v=4
twitter:cardsummary_large_image
og:imagehttps://avatars.githubusercontent.com/u/1771172?s=400&v=4
og:image:altThis replaces 2-argument super(...) calls with the zero-argument super() form everywhere applicable: All uses of two-argument super in the code are replaced. All but one mention of two-argument su...
og:site_nameGitHub
og:typeobject
hostnamegithub.com
expected-hostnamegithub.com
Nonee6156bd4ef9f2dc8dadf4c49a8f7ed8532186388cef72eda3ccb9f0ab3b8cfca
turbo-cache-controlno-preview
go-importgithub.com/gitpython-developers/GitPython git https://github.com/gitpython-developers/GitPython.git
octolytics-dimension-user_id503709
octolytics-dimension-user_logingitpython-developers
octolytics-dimension-repository_id1126087
octolytics-dimension-repository_nwogitpython-developers/GitPython
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id1126087
octolytics-dimension-repository_network_root_nwogitpython-developers/GitPython
turbo-body-classeslogged-out env-production page-responsive full-width full-width-p-0
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
releaseee2210c3e58153aae53400c942f8a7b4bbb43ec4
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/gitpython-developers/GitPython/pull/1726/checks#start-of-content
https://github.com/
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fgitpython-developers%2FGitPython%2Fpull%2F1726%2Fchecks
GitHub CopilotWrite better code with AIhttps://github.com/features/copilot
GitHub SparkBuild and deploy intelligent appshttps://github.com/features/spark
GitHub ModelsManage and compare promptshttps://github.com/features/models
MCP RegistryNewIntegrate external toolshttps://github.com/mcp
ActionsAutomate any workflowhttps://github.com/features/actions
CodespacesInstant dev environmentshttps://github.com/features/codespaces
IssuesPlan and track workhttps://github.com/features/issues
Code ReviewManage code changeshttps://github.com/features/code-review
GitHub Advanced SecurityFind and fix vulnerabilitieshttps://github.com/security/advanced-security
Code securitySecure your code as you buildhttps://github.com/security/advanced-security/code-security
Secret protectionStop leaks before they starthttps://github.com/security/advanced-security/secret-protection
Why GitHubhttps://github.com/why-github
Documentationhttps://docs.github.com
Bloghttps://github.blog
Changeloghttps://github.blog/changelog
Marketplacehttps://github.com/marketplace
View all featureshttps://github.com/features
Enterpriseshttps://github.com/enterprise
Small and medium teamshttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
App Modernizationhttps://github.com/solutions/use-case/app-modernization
DevSecOpshttps://github.com/solutions/use-case/devsecops
DevOpshttps://github.com/solutions/use-case/devops
CI/CDhttps://github.com/solutions/use-case/ci-cd
View all use caseshttps://github.com/solutions/use-case
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
View all industrieshttps://github.com/solutions/industry
View all solutionshttps://github.com/solutions
AIhttps://github.com/resources/articles?topic=ai
Software Developmenthttps://github.com/resources/articles?topic=software-development
DevOpshttps://github.com/resources/articles?topic=devops
Securityhttps://github.com/resources/articles?topic=security
View all topicshttps://github.com/resources/articles
Customer storieshttps://github.com/customer-stories
Events & webinarshttps://github.com/resources/events
Ebooks & reportshttps://github.com/resources/whitepapers
Business insightshttps://github.com/solutions/executive-insights
GitHub Skillshttps://skills.github.com
Documentationhttps://docs.github.com
Customer supporthttps://support.github.com
Community forumhttps://github.com/orgs/community/discussions
Trust centerhttps://github.com/trust-center
Partnershttps://github.com/partners
GitHub SponsorsFund open source developershttps://github.com/sponsors
Security Labhttps://securitylab.github.com
Maintainer Communityhttps://maintainers.github.com
Acceleratorhttps://github.com/accelerator
Archive Programhttps://archiveprogram.github.com
Topicshttps://github.com/topics
Trendinghttps://github.com/trending
Collectionshttps://github.com/collections
Enterprise platformAI-powered developer platformhttps://github.com/enterprise
GitHub Advanced SecurityEnterprise-grade security featureshttps://github.com/security/advanced-security
Copilot for BusinessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/premium-support
Pricinghttps://github.com/pricing
Search syntax tipshttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
documentationhttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fgitpython-developers%2FGitPython%2Fpull%2F1726%2Fchecks
Sign up https://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fpull_requests%2Fshow%2Fchecks&source=header-repo&source_repo=gitpython-developers%2FGitPython
Reloadhttps://github.com/gitpython-developers/GitPython/pull/1726/checks
Reloadhttps://github.com/gitpython-developers/GitPython/pull/1726/checks
Reloadhttps://github.com/gitpython-developers/GitPython/pull/1726/checks
gitpython-developers https://github.com/gitpython-developers
GitPythonhttps://github.com/gitpython-developers/GitPython
Please reload this pagehttps://github.com/gitpython-developers/GitPython/pull/1726/checks
Notifications https://github.com/login?return_to=%2Fgitpython-developers%2FGitPython
Fork 964 https://github.com/login?return_to=%2Fgitpython-developers%2FGitPython
Star 5k https://github.com/login?return_to=%2Fgitpython-developers%2FGitPython
Code https://github.com/gitpython-developers/GitPython
Issues 169 https://github.com/gitpython-developers/GitPython/issues
Pull requests 8 https://github.com/gitpython-developers/GitPython/pulls
Discussions https://github.com/gitpython-developers/GitPython/discussions
Actions https://github.com/gitpython-developers/GitPython/actions
Security Uh oh! There was an error while loading. Please reload this page. https://github.com/gitpython-developers/GitPython/security
Please reload this pagehttps://github.com/gitpython-developers/GitPython/pull/1726/checks
Insights https://github.com/gitpython-developers/GitPython/pulse
Code https://github.com/gitpython-developers/GitPython
Issues https://github.com/gitpython-developers/GitPython/issues
Pull requests https://github.com/gitpython-developers/GitPython/pulls
Discussions https://github.com/gitpython-developers/GitPython/discussions
Actions https://github.com/gitpython-developers/GitPython/actions
Security https://github.com/gitpython-developers/GitPython/security
Insights https://github.com/gitpython-developers/GitPython/pulse
Sign up for GitHub https://github.com/signup?return_to=%2Fgitpython-developers%2FGitPython%2Fissues%2Fnew%2Fchoose
terms of servicehttps://docs.github.com/terms
privacy statementhttps://docs.github.com/privacy
Sign inhttps://github.com/login?return_to=%2Fgitpython-developers%2FGitPython%2Fissues%2Fnew%2Fchoose
Byronhttps://github.com/Byron
gitpython-developers:mainhttps://github.com/gitpython-developers/GitPython/tree/main
EliahKagan:superhttps://github.com/EliahKagan/GitPython/tree/super
Conversation 3 https://github.com/gitpython-developers/GitPython/pull/1726
Commits 3 https://github.com/gitpython-developers/GitPython/pull/1726/commits
Checks 0 https://github.com/gitpython-developers/GitPython/pull/1726/checks
Files changed https://github.com/gitpython-developers/GitPython/pull/1726/files
Please reload this pagehttps://github.com/gitpython-developers/GitPython/pull/1726/checks
Please reload this pagehttps://github.com/gitpython-developers/GitPython/pull/1726/checks
Use zero-argument super() https://github.com/gitpython-developers/GitPython/pull/1726/checks#top
Please reload this pagehttps://github.com/gitpython-developers/GitPython/pull/1726/checks
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.