Title: Support for not following symlinks in pathlib.Path.is_dir() · Issue #105793 · python/cpython · GitHub
Open Graph Title: Support for not following symlinks in pathlib.Path.is_dir() · Issue #105793 · python/cpython
X Title: Support for not following symlinks in pathlib.Path.is_dir() · Issue #105793 · python/cpython
Description: Feature or enhancement Add a follow_symlinks argument to pathlib.Path.is_dir(), defaulting to True Pitch Pathlib's walk() and glob() implementations are built upon os.scandir(), which yields os.DirEntry objects. The interface for os.DirE...
Open Graph Description: Feature or enhancement Add a follow_symlinks argument to pathlib.Path.is_dir(), defaulting to True Pitch Pathlib's walk() and glob() implementations are built upon os.scandir(), which yields os.Dir...
X Description: Feature or enhancement Add a follow_symlinks argument to pathlib.Path.is_dir(), defaulting to True Pitch Pathlib's walk() and glob() implementations are built upon os.scandir(), which yields os...
Opengraph URL: https://github.com/python/cpython/issues/105793
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Support for not following symlinks in pathlib.Path.is_dir()","articleBody":"# Feature or enhancement\r\n\r\nAdd a *follow_symlinks* argument to [`pathlib.Path.is_dir()`](https://docs.python.org/3/library/pathlib.html#pathlib.Path.is_dir), defaulting to `True`\r\n\r\n# Pitch\r\n\r\nPathlib's `walk()` and `glob()` implementations are built upon `os.scandir()`, which yields `os.DirEntry` objects. The interface for `os.DirEntry` is a rough subset of `pathlib.Path`, including the [`name`](https://docs.python.org/3/library/os.html#os.DirEntry.name) attribute and [`is_dir()`](https://docs.python.org/3/library/os.html#os.DirEntry.is_dir) method.\r\n\r\nPathlib only ever calls `os.scandir()` via a private `pathlib.Path._scandir()` method, currently defined as follows:\r\n\r\n```python\r\n def _scandir(self):\r\n return os.scandir(self)\r\n```\r\n\r\nIn future I'd like to add a `pathlib.AbstractPath` class with abstract `stat()`, `iterdir()` and `open()` methods. \r\n\r\nThe default implementation of `AbstractPath._scandir()` would use `iterdir()`:\r\n\r\n```python\r\n def _scandir(self):\r\n return contextlib.nullcontext(list(self.iterdir()))\r\n```\r\n\r\nNote how it returns `AbstractPath` objects, and not `DirEntry` objects. This exploits the similarities of the `Path` and `DirEntry` APIs.\r\n\r\n... but there's a problem!\r\n\r\nThe `os.DirEntry.is_dir()` method accepts a keyword-only `follow_symlinks` argument. Our globbing implementation requires us to set this argument. But the `Path.is_dir()` method does not accept this argument!\r\n\r\nIf we add a keyword-only *follow_symlinks* argument to `Path.is_dir()`, we make it compatible with `os.DirEntry.is_dir()`, which in turn allows us to build a `glob()` implementation upon user-defined `stat()` and `iterdir()` methods in a future `AbstractPath` class.\r\n\r\n# Previous discussion\r\n\r\nGeneral discussion of `AbstractPath`: https://discuss.python.org/t/make-pathlib-extensible/3428\r\n\r\nWe added a *follow_symlinks* argument to `Path.exists()` in #89769 / #29655.\n\n\u003c!-- gh-linked-prs --\u003e\n### Linked PRs\n* gh-105794\n\u003c!-- /gh-linked-prs --\u003e\n","author":{"url":"https://github.com/barneygale","@type":"Person","name":"barneygale"},"datePublished":"2023-06-14T17:04:20.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":2},"url":"https://github.com/105793/cpython/issues/105793"}
| 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:a855bae7-0e2a-2f71-d064-157dc7f9a7a1 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | B812:10A5B6:13DC58A:1B64B28:6969FFC0 |
| html-safe-nonce | 12694797d895219c8292a2ad4ddd2d52f4e426c2951addac1cf56ec3e923c922 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCODEyOjEwQTVCNjoxM0RDNThBOjFCNjRCMjg6Njk2OUZGQzAiLCJ2aXNpdG9yX2lkIjoiMzk3MjkxMzA0MDU0ODU2MDgzMiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 096961632fc43759c68500914692657d2397944a7af1aec201865de2398405b2 |
| hovercard-subject-tag | issue:1757321219 |
| 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/105793/issue_layout |
| twitter:image | https://opengraph.githubassets.com/6f8bc354eff901c1a0085dc0ace6be45c9b7de3714d88e6474fda2521f0bc848/python/cpython/issues/105793 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/6f8bc354eff901c1a0085dc0ace6be45c9b7de3714d88e6474fda2521f0bc848/python/cpython/issues/105793 |
| og:image:alt | Feature or enhancement Add a follow_symlinks argument to pathlib.Path.is_dir(), defaulting to True Pitch Pathlib's walk() and glob() implementations are built upon os.scandir(), which yields os.Dir... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | barneygale |
| hostname | github.com |
| expected-hostname | github.com |
| None | 7b32f1c7c4549428ee399213e8345494fc55b5637195d3fc5f493657579235e8 |
| 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 | bdde15ad1b403e23b08bbd89b53fbe6bdf688cad |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width