René's URL Explorer Experiment


Title: Submodule.iter_items sometimes attaches second empty iterator to its StopIteration · Issue #1779 · gitpython-developers/GitPython · GitHub

Open Graph Title: Submodule.iter_items sometimes attaches second empty iterator to its StopIteration · Issue #1779 · gitpython-developers/GitPython

X Title: Submodule.iter_items sometimes attaches second empty iterator to its StopIteration · Issue #1779 · gitpython-developers/GitPython

Description: This is minor bug, and the main benefit of fixing it may be an improvement in code clarity rather than the behavioral difference. I think it makes sense to fix this in the same pull request that fixes #1775, and I've opened #1780 for tha...

Open Graph Description: This is minor bug, and the main benefit of fixing it may be an improvement in code clarity rather than the behavioral difference. I think it makes sense to fix this in the same pull request that fi...

X Description: This is minor bug, and the main benefit of fixing it may be an improvement in code clarity rather than the behavioral difference. I think it makes sense to fix this in the same pull request that fi...

Opengraph URL: https://github.com/gitpython-developers/GitPython/issues/1779

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Submodule.iter_items sometimes attaches second empty iterator to its StopIteration","articleBody":"*This is minor bug, and the main benefit of fixing it may be an improvement in code clarity rather than the behavioral difference. I think it makes sense to fix this in the same pull request that fixes #1775, and I've opened #1780 for that, but I think it's clearer to document it here than in the pull request.*\r\n\r\n`Submodule.iter_items` is a generator function as intended, because `yield` appears in its scope:\r\n\r\nhttps://github.com/gitpython-developers/GitPython/blob/d986a59467e586afb815d71845f29b605b756cdf/git/objects/submodule/base.py#L1445-L1446\r\n\r\nSometimes when one writes a function that returns a generator object, it is a regular function rather than a generator function, because the function returns a generator expression or because it calls another function that returns a generator object. That technique is sometimes used to fail fast on errors, since calling a generator function does not immediately run its code, but only returns a generator object, and the code runs when that generator object is iterated. However, that is not done here. That it is not appears intentional and reasonable, and even if not, changing it would probably break backwards compatibility.\r\n\r\nHowever, it contains this code, at the top:\r\n\r\nhttps://github.com/gitpython-developers/GitPython/blob/d986a59467e586afb815d71845f29b605b756cdf/git/objects/submodule/base.py#L1400-L1405\r\n\r\nThe intention there is to make it so that calling `iter_items` returns an empty iterator when either of those two exceptions is raised. It succeeds at doing that, but its success is unrelated to using `iter([])` as the operand of `return`. Returning from a generator function--like falling off the end, which is more common--causes there to be no more items to iterate through, so a `next` call in which this happens raises `StopIteration`.\r\n\r\nThe operand of `return` in a generator function is neither returned to the caller--a generator object is returned--nor returned when `next` is called on that generator object. Instead, it becomes *the `value` attribute* of the `StopIteration` exception raised on the `next` call to indicate there are no more values. This feature of generators is rarely used, and the common ways of using generators, such as a `for` loop, ignore it. (When `yield from` is used as an expression, it evaluates to that value, which allows generators to get status information from their subgenerators, in the rare case their subgenerators return a meaningful value. It can also be accessed directly by explicitly catching `StopIteration`, binding the exception object to a variable, and accessing its `value` attribute. That's about it.)\r\n\r\nI suppose it might make sense for `Submodule.iter_items` to have its returned generator object signal, in some way, that it is empty due to `OSError` (`IOError` and `OSError` are the same in Python 3) or `BadName`. But I think that having it attach a second empty iterator object to the `StopIteration` exception is clearly not intended to do so.\r\n\r\nThe statement was originally a bare `return`. The `iter([])` operand was added in 82b131c (#1282). It came in along with numerous additions and improvements in type hinting, and it looks like it was mistakenly added with the idea it might be needed for make type-checking succeed. However, I don't believe the major type checkers were as stable back then as they are today, so perhaps it was instead added as a workaround for a bug in a static type checker.\r\n\r\nInterestingly, this is conceptually related to #1755, and I would've fixed it there, had I been aware of it at that time. The logic in the body `Submodule.iter_items` usually implicitly \"returns\" `None` by falling off the end (and `None` is bound as the `StopIteration` exception's `value` attribute), which is its intended behavior, but sometimes it inadvertently \"returns\" a `list_iterator` object instead.","author":{"url":"https://github.com/EliahKagan","@type":"Person","name":"EliahKagan"},"datePublished":"2023-12-22T09:53:07.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":2},"url":"https://github.com/1779/GitPython/issues/1779"}

route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:33c49df5-9097-1bf2-7c78-82493485f652
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idC2AE:D065:77E4F:A1F21:69681904
html-safe-nonced999b78b4c11b237b82cf67a05b805b4ae0cd8973b55e3e0c8c8938c26c1dd12
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDMkFFOkQwNjU6NzdFNEY6QTFGMjE6Njk2ODE5MDQiLCJ2aXNpdG9yX2lkIjoiMzM4MzU0NjI4NTE4MjY4NzQ5MyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9
visitor-hmac025698d6c8038c2d47355cf79889fb13d84e6653be8336565bd2b06dc25b6d58
hovercard-subject-tagissue:2053669402
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/gitpython-developers/GitPython/1779/issue_layout
twitter:imagehttps://opengraph.githubassets.com/1eca1511cd843ab0132567d57ba042b2574578d4230df91a6cf8424ef888bfe0/gitpython-developers/GitPython/issues/1779
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/1eca1511cd843ab0132567d57ba042b2574578d4230df91a6cf8424ef888bfe0/gitpython-developers/GitPython/issues/1779
og:image:altThis is minor bug, and the main benefit of fixing it may be an improvement in code clarity rather than the behavioral difference. I think it makes sense to fix this in the same pull request that fi...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernameEliahKagan
hostnamegithub.com
expected-hostnamegithub.com
None2452ef75cc61e096c7ab0f8a4fca0ff7d45789bc2e145182d98e41a6ba61e5e1
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
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release424b2f45b6311b8635b559db771ca199ff3a1b4f
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/gitpython-developers/GitPython/issues/1779#start-of-content
https://github.com/
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fgitpython-developers%2FGitPython%2Fissues%2F1779
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%2Fissues%2F1779
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%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=gitpython-developers%2FGitPython
Reloadhttps://github.com/gitpython-developers/GitPython/issues/1779
Reloadhttps://github.com/gitpython-developers/GitPython/issues/1779
Reloadhttps://github.com/gitpython-developers/GitPython/issues/1779
gitpython-developers https://github.com/gitpython-developers
GitPythonhttps://github.com/gitpython-developers/GitPython
Please reload this pagehttps://github.com/gitpython-developers/GitPython/issues/1779
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/issues/1779
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
New issuehttps://github.com/login?return_to=https://github.com/gitpython-developers/GitPython/issues/1779
New issuehttps://github.com/login?return_to=https://github.com/gitpython-developers/GitPython/issues/1779
#1780https://github.com/gitpython-developers/GitPython/pull/1780
Submodule.iter_items sometimes attaches second empty iterator to its StopIterationhttps://github.com/gitpython-developers/GitPython/issues/1779#top
#1780https://github.com/gitpython-developers/GitPython/pull/1780
acknowledgedhttps://github.com/gitpython-developers/GitPython/issues?q=state%3Aopen%20label%3A%22acknowledged%22
https://github.com/EliahKagan
https://github.com/EliahKagan
EliahKaganhttps://github.com/EliahKagan
on Dec 22, 2023https://github.com/gitpython-developers/GitPython/issues/1779#issue-2053669402
#1775https://github.com/gitpython-developers/GitPython/issues/1775
#1780https://github.com/gitpython-developers/GitPython/pull/1780
GitPython/git/objects/submodule/base.pyhttps://github.com/gitpython-developers/GitPython/blob/d986a59467e586afb815d71845f29b605b756cdf/git/objects/submodule/base.py#L1445-L1446
d986a59https://github.com/gitpython-developers/GitPython/commit/d986a59467e586afb815d71845f29b605b756cdf
GitPython/git/objects/submodule/base.pyhttps://github.com/gitpython-developers/GitPython/blob/d986a59467e586afb815d71845f29b605b756cdf/git/objects/submodule/base.py#L1400-L1405
d986a59https://github.com/gitpython-developers/GitPython/commit/d986a59467e586afb815d71845f29b605b756cdf
82b131chttps://github.com/gitpython-developers/GitPython/commit/82b131cf2afebbed3723df5b5dfd5cd820716f97
#1282https://github.com/gitpython-developers/GitPython/pull/1282
#1755https://github.com/gitpython-developers/GitPython/pull/1755
acknowledgedhttps://github.com/gitpython-developers/GitPython/issues?q=state%3Aopen%20label%3A%22acknowledged%22
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.