René's URL Explorer Experiment


Title: is_darwin is always False (os.name is never "darwin") · Issue #1731 · gitpython-developers/GitPython · GitHub

Open Graph Title: is_darwin is always False (os.name is never "darwin") · Issue #1731 · gitpython-developers/GitPython

X Title: is_darwin is always False (os.name is never "darwin") · Issue #1731 · gitpython-developers/GitPython

Description: As discussed in #1679 and #1679 (review), code inside or outside of GitPython that uses is_win from git.compat is prone to bugs, because it is easy to assume wrongly that is_win would be true on Cygwin. Instead, is_win is short for os.na...

Open Graph Description: As discussed in #1679 and #1679 (review), code inside or outside of GitPython that uses is_win from git.compat is prone to bugs, because it is easy to assume wrongly that is_win would be true on Cy...

X Description: As discussed in #1679 and #1679 (review), code inside or outside of GitPython that uses is_win from git.compat is prone to bugs, because it is easy to assume wrongly that is_win would be true on Cy...

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

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"is_darwin is always False (os.name is never \"darwin\")","articleBody":"As discussed in #1679 and https://github.com/gitpython-developers/GitPython/pull/1679#pullrequestreview-1644389896, code inside or outside of GitPython that uses `is_win` from `git.compat` is prone to bugs, because it is easy to assume wrongly that `is_win` would be true on Cygwin. Instead, `is_win` is short for `os.name == \"nt\"`, and writing that out makes clearer what one is testing.\r\n\r\nHowever, I have discovered that the potential for confusion in using the `is_\u003cplatform\u003e` aliases in `git.compat` is not limited to `is_win`. Specifically, **`is_darwin` is always `False`, including on macOS systems**.\r\n\r\nThis is because `is_darwin` is short for `os.name == \"darwin\"`, but `\"darwin\"` [is not currently](https://docs.python.org/3/library/os.html#os.name) and [seems never to have been](https://docs.python.org/2.7/library/os.html#os.name) one of the possible values of `os.name`. In Python 2, there were more values of `os.name` than in Python 3, but in both languages `os.name` is always `\"posix\"` on the operating system today called macOS (historically called Mac OS X, with Mac OS 9 and earlier not being POSIX systems).\r\n\r\nIn the infrequent case that one wishes to test for macOS, one can check `sys.platform == \"darwin\"`, because `sys.platform` is more granular than `os.name` and does take on the value of `\"darwin\"` on macOS. GitPython does not currently need to do this, and no uses of `is_darwin` appear in `git/` or `test/` currently. This appears to have been the case since 4545762 (#1295).\r\n\r\nThe buggy definition of `is_darwin` seems to have had limited impact in the project, having been introduced in f495e94 (part of #519) and only used in a couple of places, then none since #1295. Before #519, the correct expression `sys.platform == 'darwin'` was used, but it seems to have been inadvertently changed to the always-false `os.name == 'darwin'` [in that commit](https://github.com/gitpython-developers/GitPython/commit/f495e94028bfddc264727ffc464cd694ddd05ab8#diff-2f2b548c14a71e5bbf15502f6d7fd98a50842119152c451ae2ec5e1cc42f02d2). (The `is_\u003cplatform\u003e` attributes were soon after changed from functions to variables/constants in e61439b, which was also in #519.)\r\n\r\n### Possible fixes\r\n\r\nAlthough GitPython doesn't use `is_darwin` anymore, it is a public name in `git.compat` (since that module does not define `__all__` and the name `is_darwin` neither starts with a `_` nor has been documented as nonpublic). So it may be in other projects that use GitPython. If so, those other projects suffer either from this bug, or if not then from another bug of their own where they depend on `is_darwin` having the wrong value.\r\n\r\nBecause removing it would be a breaking change, it should probably be kept, but fixed to use the expression `sys.platform == \"darwin\"`. However, this does have the disadvantage that a developer who checks its implementation may assume `is_win` and `is_posix` are analogous, examining `sys.platform`. In the case of `is_win`, which checks `os.name = \"nt\"`, I believe it is currently equivalent to checking `sys.platform == \"win32\"`, though historically this may not always have been the case. In the case of `is_posix`, however, it is not equivalent to any straightforward expression with `sys.platform`, because a few \"POSIX\" platforms are distinguished with custom values of `sys.platform`.\r\n\r\nBoth for this reason and, more so, because of the confusion that turns out to have arisen from the `is_\u003cplatform\u003e` aliases, I recommend all of them be replaced, and also that they be documented as deprecated. Because deprecation is often not readily discovered when one is not looking for it--even if `DeprecationWarning` is emitted, that warning is hidden by default--I think `is_darwin` should probably be fixed to `sys.platform == \"darwin\"` as well, in spite of the disadvantages of doing so.\r\n\r\nA further benefit of replacing all uses is that static type checkers (and some editors) understand checks against standard-library attributes such as `os.name` and they are able to check code more precisely based on them. This helps with things like flags in the `subprocess` module that differ across platforms (though attribute accesses based on them have to be written across separate expressions, rather than for example in a ternary expression, to get the full benefit of these distinctions, at least with current type checkers). As far as I know, there's no fundamental reason this shouldn't also work with module attributes assigned that kind of expression (typing it automatically as a literal value), but that does not seem to happen.\r\n\r\nI've opened #1732 for this. For the reasons given below, I haven't included any code to emit new `DeprecationWarning`s, though I'd be pleased to do so if requested.\r\n\r\n### New warnings?\r\n\r\nAlthough I recommend the `is_\u003cplatform\u003e` attributes be deprecated, I am unsure if it is worthwhile to have accesses to those attributes raise any warnings at this time. There are a few considerations:\r\n\r\n- This can be done by defining a module-level `__getattr__`, but I think that slightly decreases the benefits of static typing. It can also be done by writing a class that inherits from `types.ModuleType` and defines properties, and assigning that class to the `__class__` attribute of the module object. This may be preferable, *if* it turns out to play better with static typing. See [Customizing module attribute access](https://docs.python.org/3/reference/datamodel.html#customizing-module-attribute-access) (though it doesn't discuss static typing implications).\r\n- It seems very likely that `DeprecationWarning`s on particular module-level attribute accesses will be of use elsewhere in the project. (One possible place is for `__version__` as discussed in [this](https://github.com/gitpython-developers/GitPython/issues/1716#issuecomment-1773728098) and [that](https://github.com/gitpython-developers/GitPython/issues/1716#issuecomment-1773746757) comment, but I think there may be a number of others, too.) But I'd be more comfortable introducing either of these things once static typing is in better shape, so their effects on that can be better judged.\r\n- There is also a more specific and, in my view, important reason to be reluctant to add this functionality for those attributes right now: they are in `git.compat`, which could perhaps be *entirely* deprecated sometime soon. That module's original purpose was to help in supporting both Python 2 and Python 3. Since GitPython currently only supports Python 3, it might be possible to eliminate use of *all* of the facilities in `git.compat`, though whether or not that *should* be done is another question, since some uses of it might be considered to improve clarity for reasons not tied to the distinction between Python 2 and Python 3. But if `git.compat` as a whole is deprecated, then emitting a `DeprecationWarning` won't require any special attribute handling, as it can just be done with a top-level `warnings.warn` call in the module.","author":{"url":"https://github.com/EliahKagan","@type":"Person","name":"EliahKagan"},"datePublished":"2023-11-04T21:20:33.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":0},"url":"https://github.com/1731/GitPython/issues/1731"}

route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:c78147f9-6447-da2c-eae7-5501768c3041
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idA63A:6A14:34F7FB1:35A18F4:69684F12
html-safe-nonce821e1ddbd9f0c3d54d69b8c4b39a35f072c5fcf355e872b5fba26e475b752894
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBNjNBOjZBMTQ6MzRGN0ZCMTozNUExOEY0OjY5Njg0RjEyIiwidmlzaXRvcl9pZCI6Ijc1NTk0MTQzMTQxNTgyODA0NjYiLCJyZWdpb25fZWRnZSI6InNlYSIsInJlZ2lvbl9yZW5kZXIiOiJzZWEifQ==
visitor-hmacc54da2388e2437264be0c63aec748bda3ab7f370f2a2aa617bcf7f0700f1fc7a
hovercard-subject-tagissue:1977515389
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/1731/issue_layout
twitter:imagehttps://opengraph.githubassets.com/dc74acd80cef8d5fadd4461402222cd8f2c7d4e28ba33615120890118c885c91/gitpython-developers/GitPython/issues/1731
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/dc74acd80cef8d5fadd4461402222cd8f2c7d4e28ba33615120890118c885c91/gitpython-developers/GitPython/issues/1731
og:image:altAs discussed in #1679 and #1679 (review), code inside or outside of GitPython that uses is_win from git.compat is prone to bugs, because it is easy to assume wrongly that is_win would be true on Cy...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernameEliahKagan
hostnamegithub.com
expected-hostnamegithub.com
Nonef16c57f41ed243e5b4dfe9b9bcd6828bd83080b1b6dbb4ff239bbe9745f12e0c
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
releasecfa7062cc6d4fe8fcb156bd33f4c97bd3b2470af
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/gitpython-developers/GitPython/issues/1731#start-of-content
https://github.com/
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fgitpython-developers%2FGitPython%2Fissues%2F1731
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%2F1731
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/1731
Reloadhttps://github.com/gitpython-developers/GitPython/issues/1731
Reloadhttps://github.com/gitpython-developers/GitPython/issues/1731
gitpython-developers https://github.com/gitpython-developers
GitPythonhttps://github.com/gitpython-developers/GitPython
Please reload this pagehttps://github.com/gitpython-developers/GitPython/issues/1731
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/1731
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/1731
New issuehttps://github.com/login?return_to=https://github.com/gitpython-developers/GitPython/issues/1731
#1732https://github.com/gitpython-developers/GitPython/pull/1732
is_darwin is always False (os.name is never "darwin")https://github.com/gitpython-developers/GitPython/issues/1731#top
#1732https://github.com/gitpython-developers/GitPython/pull/1732
https://github.com/EliahKagan
https://github.com/EliahKagan
EliahKaganhttps://github.com/EliahKagan
on Nov 4, 2023https://github.com/gitpython-developers/GitPython/issues/1731#issue-1977515389
#1679https://github.com/gitpython-developers/GitPython/pull/1679
#1679 (review)https://github.com/gitpython-developers/GitPython/pull/1679#pullrequestreview-1644389896
is not currentlyhttps://docs.python.org/3/library/os.html#os.name
seems never to have beenhttps://docs.python.org/2.7/library/os.html#os.name
4545762https://github.com/gitpython-developers/GitPython/commit/454576254b873b7ebc45bb30846e5831dc2d8817
#1295https://github.com/gitpython-developers/GitPython/pull/1295
f495e94https://github.com/gitpython-developers/GitPython/commit/f495e94028bfddc264727ffc464cd694ddd05ab8
#519https://github.com/gitpython-developers/GitPython/pull/519
#1295https://github.com/gitpython-developers/GitPython/pull/1295
#519https://github.com/gitpython-developers/GitPython/pull/519
in that commithttps://github.com/gitpython-developers/GitPython/commit/f495e94028bfddc264727ffc464cd694ddd05ab8#diff-2f2b548c14a71e5bbf15502f6d7fd98a50842119152c451ae2ec5e1cc42f02d2
e61439bhttps://github.com/gitpython-developers/GitPython/commit/e61439b3018b0b9a8eb43e59d0d7cf32041e2fed
#519https://github.com/gitpython-developers/GitPython/pull/519
#1732https://github.com/gitpython-developers/GitPython/pull/1732
Customizing module attribute accesshttps://docs.python.org/3/reference/datamodel.html#customizing-module-attribute-access
thishttps://github.com/gitpython-developers/GitPython/issues/1716#issuecomment-1773728098
thathttps://github.com/gitpython-developers/GitPython/issues/1716#issuecomment-1773746757
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.