René's URL Explorer Experiment


Title: Incorrect return type hint in `SymbolicReference.reference` leads to mypy errors · Issue #2066 · gitpython-developers/GitPython · GitHub

Open Graph Title: Incorrect return type hint in `SymbolicReference.reference` leads to mypy errors · Issue #2066 · gitpython-developers/GitPython

X Title: Incorrect return type hint in `SymbolicReference.reference` leads to mypy errors · Issue #2066 · gitpython-developers/GitPython

Description: Since GitPython 3.1.45 was released, we've had mypy reporting pre-checkin errors for code that has been stable and functional for years: error: "SymbolicReference" has no attribute "checkout" [attr-defined] error: "SymbolicReference" has...

Open Graph Description: Since GitPython 3.1.45 was released, we've had mypy reporting pre-checkin errors for code that has been stable and functional for years: error: "SymbolicReference" has no attribute "checkout" [attr...

X Description: Since GitPython 3.1.45 was released, we've had mypy reporting pre-checkin errors for code that has been stable and functional for years: error: "SymbolicReference" has no attribute &q...

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

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Incorrect return type hint in `SymbolicReference.reference` leads to mypy errors","articleBody":"Since GitPython 3.1.45 was released, we've had `mypy` reporting pre-checkin errors for code that has been stable and functional for years:\n```\nerror: \"SymbolicReference\" has no attribute \"checkout\"  [attr-defined]\nerror: \"SymbolicReference\" has no attribute \"tracking_branch\"  [attr-defined]\nerror: \"SymbolicReference\" has no attribute \"tracking_branch\"  [attr-defined]\n```\n\nThe code failing `mypy` checks is doing things like getting the active branch, so we can switch back to it after doing other stuff:\n```\n    @contextmanager\n    def checkout(self, branch: Branch) -\u003e typing.Generator[None]:\n        new_branch = self.api.create_head(branch.name)\n        current = self.api.head.ref\n        try:\n            new_branch.checkout()\n            yield\n        finally:\n            current.checkout()\n```\n\n... or ensuring that the active branch has a remote tracking branch set:\n```\n    tracking_branch = repo.head.reference.tracking_branch()\n    if tracking_branch is None:\n        raise GitConfigException(\n            'Error: Upstream branch not set; use \"git branch '\n            '--set-upstream-to=\u003cremote/branch\u003e\" to fix.'\n        )\n    if tracking_branch.remote_name == \".\":\n        raise GitConfigException(\n            'Error: Upstream branch is local rather than remote; use \"git '\n            'branch --set-upstream-to=\u003cremote/branch\u003e\" to fix.'\n        )\n``` \n\nThe immediate cause of these new `mypy` errors appears to be [this commit](https://github.com/gitpython-developers/GitPython/commit/94151aa2ca9f16491a0cf2344b4daa8bf7b41d70#diff-72d42177f0e8535634711b5de0390d5bc81dbedab1fbac6547e5b9ab3b03eb9aL52), which added a new type hint for the return value of `SymbolicReference.reference`:\n```\n    @property\n    def reference(self) -\u003e \"SymbolicReference\":\n        return self._get_reference()\n```\n\nIn manual testing I've found that the `reference` method doesn't actually return a `SymbolicReference` object when the the symbolic reference is `HEAD`. Instead, a `Head` object is returned:\n```\n\u003e\u003e\u003e import git\n\u003e\u003e\u003e git.__version__\n'3.1.45'\n\u003e\u003e\u003e testrepo = git.repo.Repo.init(\".\")\n\u003e\u003e\u003e type(testrepo.head)\n\u003cclass 'git.refs.head.HEAD'\u003e\n\u003e\u003e\u003e type(testrepo.head.ref)\n\u003cclass 'git.refs.head.Head'\u003e\n\u003e\u003e\u003e testrepo.head.ref.tracking_branch()\n\u003cgit.RemoteReference \"refs/remotes/./master\"\u003e\n\u003e\u003e\u003e testrepo.head.ref.checkout()\n\u003cgit.Head \"refs/heads/bar\"\u003e\n```","author":{"url":"https://github.com/dvanderveer","@type":"Person","name":"dvanderveer"},"datePublished":"2025-08-08T20:57:57.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":2},"url":"https://github.com/2066/GitPython/issues/2066"}

route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:dd71e4fc-32fa-6abd-7b8b-f706e0cdb563
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idB380:1C762F:5E7126:84B530:6968DEE0
html-safe-nonce0f1738dc2b0a1902f9b2748e8592d7c623a731fb2d26b98e0647622552b1b670
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCMzgwOjFDNzYyRjo1RTcxMjY6ODRCNTMwOjY5NjhERUUwIiwidmlzaXRvcl9pZCI6IjY3NzI5NzQ2MzY3MTQ0NzI2NCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9
visitor-hmac407d7502e863ddc6d5efa26520509b56497089a8761c09b9b5a4d3750ba2f856
hovercard-subject-tagissue:3305196079
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/2066/issue_layout
twitter:imagehttps://opengraph.githubassets.com/72e3e975f60d75270ed9d6e64438f9388e439f5db4b10d007eabf607ed49e83f/gitpython-developers/GitPython/issues/2066
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/72e3e975f60d75270ed9d6e64438f9388e439f5db4b10d007eabf607ed49e83f/gitpython-developers/GitPython/issues/2066
og:image:altSince GitPython 3.1.45 was released, we've had mypy reporting pre-checkin errors for code that has been stable and functional for years: error: "SymbolicReference" has no attribute "checkout" [attr...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernamedvanderveer
hostnamegithub.com
expected-hostnamegithub.com
None3c4e9f2fc1db52c609205138be6a397cfde4574cb54d53015014de30dd49f27e
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
release1fb1ea11f8c37dd4dd50347cca70d89824e93788
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/gitpython-developers/GitPython/issues/2066#start-of-content
https://github.com/
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fgitpython-developers%2FGitPython%2Fissues%2F2066
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%2F2066
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/2066
Reloadhttps://github.com/gitpython-developers/GitPython/issues/2066
Reloadhttps://github.com/gitpython-developers/GitPython/issues/2066
gitpython-developers https://github.com/gitpython-developers
GitPythonhttps://github.com/gitpython-developers/GitPython
Please reload this pagehttps://github.com/gitpython-developers/GitPython/issues/2066
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/2066
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/2066
New issuehttps://github.com/login?return_to=https://github.com/gitpython-developers/GitPython/issues/2066
#2074https://github.com/gitpython-developers/GitPython/pull/2074
Incorrect return type hint in SymbolicReference.reference leads to mypy errorshttps://github.com/gitpython-developers/GitPython/issues/2066#top
#2074https://github.com/gitpython-developers/GitPython/pull/2074
acknowledgedhttps://github.com/gitpython-developers/GitPython/issues?q=state%3Aopen%20label%3A%22acknowledged%22
https://github.com/dvanderveer
https://github.com/dvanderveer
dvanderveerhttps://github.com/dvanderveer
on Aug 8, 2025https://github.com/gitpython-developers/GitPython/issues/2066#issue-3305196079
this commithttps://github.com/gitpython-developers/GitPython/commit/94151aa2ca9f16491a0cf2344b4daa8bf7b41d70#diff-72d42177f0e8535634711b5de0390d5bc81dbedab1fbac6547e5b9ab3b03eb9aL52
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.