Title: Add `dir_fd` to `os.path.lexists()` & `os.path.isdir()` · Issue #117967 · python/cpython · GitHub
Open Graph Title: Add `dir_fd` to `os.path.lexists()` & `os.path.isdir()` · Issue #117967 · python/cpython
X Title: Add `dir_fd` to `os.path.lexists()` & `os.path.isdir()` · Issue #117967 · python/cpython
Description: Feature or enhancement Proposal: glob currently needs its own implementation of os.path.lexists() & os.path.isdir() to support dir_fd: cpython/Lib/glob.py Lines 201 to 222 in f74e512 def _lexists(pathname, dir_fd): # Same as os.path.lexi...
Open Graph Description: Feature or enhancement Proposal: glob currently needs its own implementation of os.path.lexists() & os.path.isdir() to support dir_fd: cpython/Lib/glob.py Lines 201 to 222 in f74e512 def _lexists(p...
X Description: Feature or enhancement Proposal: glob currently needs its own implementation of os.path.lexists() & os.path.isdir() to support dir_fd: cpython/Lib/glob.py Lines 201 to 222 in f74e512 def _lexis...
Opengraph URL: https://github.com/python/cpython/issues/117967
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Add `dir_fd` to `os.path.lexists()` \u0026 `os.path.isdir()`","articleBody":"# Feature or enhancement\r\n\r\n### Proposal:\r\n\r\n`glob` currently needs its own implementation of `os.path.lexists()` \u0026 `os.path.isdir()` to support `dir_fd`:\r\n\r\nhttps://github.com/python/cpython/blob/f74e51229c83e3265f905dc15283bfe0ec1a659e/Lib/glob.py#L201-L222\r\n\r\nWe could refactor this by adding `dir_fd` to `os.path.lexists()` \u0026 `os.path.isdir()`:\r\n\r\n```diff\r\n-def lexists(path):\r\n+def lexists(path, *, dir_fd: int | None = None):\r\n \"\"\"Test whether a path exists. Returns True for broken symbolic links\"\"\"\r\n try:\r\n- os.lstat(path)\r\n+ os.lstat(path, dir_fd=dir_fd)\r\n except (OSError, ValueError):\r\n return False\r\n return True\r\n```\r\n\r\n```diff\r\n-def isdir(s):\r\n+def isdir(s, *, dir_fd: int | None = None):\r\n \"\"\"Return true if the pathname refers to an existing directory.\"\"\"\r\n try:\r\n- st = os.stat(s)\r\n+ st = os.stat(s, dir_fd=dir_fd)\r\n except (OSError, ValueError):\r\n return False\r\n return stat.S_ISDIR(st.st_mode)\r\n```\r\n\r\n*Note: `nt._path_isdir()` (\u0026 `nt._path_lexists()` when #117842 lands) need to raise an error for this.*\r\n\r\n### Has this already been discussed elsewhere?\r\n\r\nThis is a minor feature, which does not need previous discussion elsewhere\r\n\r\n### Links to previous discussion of this feature:\r\n\r\n_No response_","author":{"url":"https://github.com/nineteendo","@type":"Person","name":"nineteendo"},"datePublished":"2024-04-17T08:02:43.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":8},"url":"https://github.com/117967/cpython/issues/117967"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:a89cd5fd-124d-9711-f7b3-4a49def0ee3a |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | B8E4:29B8E2:A2E2A7:E20F32:696A8651 |
| html-safe-nonce | fd507ab0c2e3e3b6c76bc5fb4bcfb713c82cc0c48e63e31118647ea50aaf50df |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCOEU0OjI5QjhFMjpBMkUyQTc6RTIwRjMyOjY5NkE4NjUxIiwidmlzaXRvcl9pZCI6IjU4MzgyMDkzMjcwODczODgyNDEiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 75b6d747c798d369a6e1cf81b5e8515f35dac2385d087b0c00367edbd0d374ed |
| hovercard-subject-tag | issue:2247649022 |
| github-keyboard-shortcuts | repository,issues,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/_view_fragments/issues/show/python/cpython/117967/issue_layout |
| twitter:image | https://opengraph.githubassets.com/20ecd4407ae9d8fccb053d12ed41bea628f8da9d2f83eab606c6b1b4173b0ba6/python/cpython/issues/117967 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/20ecd4407ae9d8fccb053d12ed41bea628f8da9d2f83eab606c6b1b4173b0ba6/python/cpython/issues/117967 |
| og:image:alt | Feature or enhancement Proposal: glob currently needs its own implementation of os.path.lexists() & os.path.isdir() to support dir_fd: cpython/Lib/glob.py Lines 201 to 222 in f74e512 def _lexists(p... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | nineteendo |
| hostname | github.com |
| expected-hostname | github.com |
| None | d2aa6dedd7d97fa651b17c40401f2605f309df5ca5fb659bf0554cf34f1de825 |
| turbo-cache-control | no-preview |
| go-import | github.com/python/cpython git https://github.com/python/cpython.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 81598961 |
| octolytics-dimension-repository_nwo | python/cpython |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 81598961 |
| octolytics-dimension-repository_network_root_nwo | python/cpython |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | c1dbca8981c5e3d6a69bce2f1d289e732b86241d |
| ui-target | canary-1 |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width