René's URL Explorer Experiment


Title: `importlib.abc.Traversable.read_text()` incompatible with `importlib.resources._functional.read_text()` usage (Python 3.13) · Issue #127012 · python/cpython · GitHub

Open Graph Title: `importlib.abc.Traversable.read_text()` incompatible with `importlib.resources._functional.read_text()` usage (Python 3.13) · Issue #127012 · python/cpython

X Title: `importlib.abc.Traversable.read_text()` incompatible with `importlib.resources._functional.read_text()` usage (Python 3.13) · Issue #127012 · python/cpython

Description: Bug report Bug description: I'm writing a custom importer and discovered that the function signature for importlib.abc.Traversable.read_text() is incompatible with the usage in importlib.resources._functional.read_text(), specifically on...

Open Graph Description: Bug report Bug description: I'm writing a custom importer and discovered that the function signature for importlib.abc.Traversable.read_text() is incompatible with the usage in importlib.resources....

X Description: Bug report Bug description: I'm writing a custom importer and discovered that the function signature for importlib.abc.Traversable.read_text() is incompatible with the usage in importlib.resour...

Opengraph URL: https://github.com/python/cpython/issues/127012

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"`importlib.abc.Traversable.read_text()` incompatible with `importlib.resources._functional.read_text()` usage (Python 3.13)","articleBody":"# Bug report\r\n\r\n### Bug description:\r\n\r\nI'm writing a custom importer and discovered that the function signature for `importlib.abc.Traversable.read_text()` is incompatible with the usage in `importlib.resources._functional.read_text()`, specifically on Python 3.13.\r\n\r\n1. `importlib.abc.Traversable.read_text()` is a concrete method; its implementation calls the `.open()` method, which is an abstract method that must be implemented. The expectation is therefore that implementing `.open()` in a Traversable subclass is sufficient for `.read_text()` to work.\r\n\r\n   Note below that the `.read_text()` method is not marked as abstract, and includes only one parameter: `encoding`:\r\n\r\n   https://github.com/python/cpython/blob/30aeb00d367d0cc9e5a7603371636cddea09f1c0/Lib/importlib/resources/abc.py#L84-L90\r\n\r\n2. Application code that attempts to read a package resource, like `importlib.resources.read_text(module, \"resource.txt\")` ultimately leads to a call to `importlib.resources._functional.read_text()`, which attempts to call the `.read_text()` method of a Traversable subclass, but includes an `errors` parameter that doesn't exist in Traversable's default concrete method:\r\n\r\n   https://github.com/python/cpython/blob/30aeb00d367d0cc9e5a7603371636cddea09f1c0/Lib/importlib/resources/_functional.py#L28-L32\r\n\r\n3. Consequently, it appears to be necessary for all Traversable subclasses to not only re-implement its concrete `.read_text()` method, but also to override its signature.\r\n\r\nI think that the Traversable `.read_text()` method signature, and the call site in `importlib.resources._functional.read_text()`, need to align with each other.\r\n\r\n**_I'd like to submit a PR for this!_** However, I would like confirmation that an `errors` parameter should be added to the `Traversable.read_text()` method.\r\n\r\nNote that adding an `errors` parameter was previously discussed in #88368.\r\n\r\n## Demonstration of TypeError bug\r\n\r\n```python\r\nimport io\r\nimport sys\r\nimport typing\r\nimport pathlib\r\nimport types\r\nimport importlib.abc\r\nimport importlib.machinery\r\nimport importlib.metadata\r\nimport importlib.resources.abc\r\n\r\n\r\nclass ExampleFinder(importlib.abc.MetaPathFinder):\r\n    def find_spec(\r\n        self,\r\n        fullname: str,\r\n        path: typing.Sequence[str] | None,\r\n        target: types.ModuleType | None = None,\r\n    ) -\u003e importlib.machinery.ModuleSpec | None:\r\n        if fullname != \"demonstrate_error\":\r\n            return None\r\n\r\n        print(f\"ExampleFinder.find_spec('{fullname}')\")\r\n        spec = importlib.machinery.ModuleSpec(\r\n            name=fullname,\r\n            loader=ExampleLoader(),\r\n            is_package=True,\r\n        )\r\n        return spec\r\n\r\n\r\nsys.meta_path.append(ExampleFinder())\r\n\r\n\r\nclass ExampleLoader(importlib.abc.Loader):\r\n    def exec_module(self, module: types.ModuleType) -\u003e None:\r\n        print(f\"ExampleLoader.exec_module({module})\")\r\n        exec(\"\", module.__dict__)\r\n\r\n    def get_resource_reader(self, fullname: str) -\u003e \"ExampleTraversableResources\":\r\n        print(f\"ExampleLoader.get_resource_reader('{fullname}')\")\r\n        return ExampleTraversableResources(fullname)\r\n\r\n\r\nclass ExampleTraversableResources(importlib.resources.abc.TraversableResources):\r\n    def __init__(self, fullname: str) -\u003e None:\r\n        self.fullname = fullname\r\n\r\n    def files(self) -\u003e \"ExampleTraversable\":\r\n        print(\"ExampleTraversableResources.files()\")\r\n        return ExampleTraversable(self.fullname)\r\n\r\n\r\n# ----------------------------------------------------------------------------\r\n# ExampleTraversable implements all five of the Traversable abstract methods.\r\n# Specifically, it is expected that implementing `.open()` will be sufficient,\r\n# but this will not be the case.\r\n#\r\n\r\nclass ExampleTraversable(importlib.resources.abc.Traversable):\r\n    def __init__(self, path: str):\r\n        self._path = path\r\n\r\n    def iterdir(self) -\u003e typing.Iterator[\"ExampleTraversable\"]:\r\n        yield ExampleTraversable(\"resource.txt\")\r\n\r\n    def is_dir(self) -\u003e bool:\r\n        return False\r\n\r\n    def is_file(self) -\u003e bool:\r\n        return True\r\n\r\n    def open(self, mode='r', *args, **kwargs) -\u003e typing.IO[typing.AnyStr]:\r\n        return io.StringIO(\"Nice! The call to .read_text() succeeded!\")\r\n\r\n    # Uncomment this `.read_text()` method to make `.read_text()` calls work.\r\n    # It overrides the `Traversable.read_text()` signature.\r\n    #\r\n    # def read_text(self, encoding: str | None, errors: str | None) -\u003e str:\r\n    #     print(f\"ExampleTraversable.read_text('{encoding}', '{errors}')\")\r\n    #     return str(super().read_text(encoding))\r\n\r\n    @property\r\n    def name(self) -\u003e str:\r\n        return pathlib.PurePosixPath(self._path).name\r\n\r\n\r\n# -------------------------------------------------------------------------------\r\n# Everything above allows us to import this hard-coded module\r\n# and demonstrate a TypeError lurking in the Traversable.read_text() signature.\r\n#\r\n\r\nimport demonstrate_error\r\n\r\n\r\n# The next line will raise a TypeError.\r\n# `importlib/resources/_functional.py:read_text()` calls `Traversable.read_text()`\r\n# with an `errors` argument that is not supported by the default concrete method.\r\nprint(importlib.resources.read_text(demonstrate_error, \"resource.txt\"))\r\n```\r\n\r\n### CPython versions tested on:\r\n\r\n3.13\r\n\r\n### Operating systems tested on:\r\n\r\nLinux","author":{"url":"https://github.com/kurtmckee","@type":"Person","name":"kurtmckee"},"datePublished":"2024-11-19T13:28:01.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":13},"url":"https://github.com/127012/cpython/issues/127012"}

route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:ea833325-ab63-d952-fcbf-b88920994e14
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idEBD6:178041:41C189:5B8862:696A6A3A
html-safe-nonce01a0f4a410822a02f1fc6eda46b48bd5362b94b0b35c3e368379f98ed46f7089
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFQkQ2OjE3ODA0MTo0MUMxODk6NUI4ODYyOjY5NkE2QTNBIiwidmlzaXRvcl9pZCI6IjQ5NzE5NDIzOTIzMTEyMTI2MDIiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ==
visitor-hmac6d72359780deecd9b562937484576b3373b0ed8a50f56fc092bfdd74395fbe42
hovercard-subject-tagissue:2672194534
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/python/cpython/127012/issue_layout
twitter:imagehttps://opengraph.githubassets.com/cd4b0bfa949d7348ac97172c35d0638b343bdadd0eded6ab3305bf7891bc1499/python/cpython/issues/127012
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/cd4b0bfa949d7348ac97172c35d0638b343bdadd0eded6ab3305bf7891bc1499/python/cpython/issues/127012
og:image:altBug report Bug description: I'm writing a custom importer and discovered that the function signature for importlib.abc.Traversable.read_text() is incompatible with the usage in importlib.resources....
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernamekurtmckee
hostnamegithub.com
expected-hostnamegithub.com
None6fea32d5b7276b841b7a803796d9715bc6cfb31ed549fdf9de2948ac25d12ba6
turbo-cache-controlno-preview
go-importgithub.com/python/cpython git https://github.com/python/cpython.git
octolytics-dimension-user_id1525981
octolytics-dimension-user_loginpython
octolytics-dimension-repository_id81598961
octolytics-dimension-repository_nwopython/cpython
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id81598961
octolytics-dimension-repository_network_root_nwopython/cpython
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
releasef2d9f6432a5a115ec709295ae70623f33bb80aee
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/python/cpython/issues/127012#start-of-content
https://github.com/
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fissues%2F127012
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%2Fpython%2Fcpython%2Fissues%2F127012
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=python%2Fcpython
Reloadhttps://github.com/python/cpython/issues/127012
Reloadhttps://github.com/python/cpython/issues/127012
Reloadhttps://github.com/python/cpython/issues/127012
python https://github.com/python
cpythonhttps://github.com/python/cpython
Please reload this pagehttps://github.com/python/cpython/issues/127012
Notifications https://github.com/login?return_to=%2Fpython%2Fcpython
Fork 33.9k https://github.com/login?return_to=%2Fpython%2Fcpython
Star 71.1k https://github.com/login?return_to=%2Fpython%2Fcpython
Code https://github.com/python/cpython
Issues 5k+ https://github.com/python/cpython/issues
Pull requests 2.1k https://github.com/python/cpython/pulls
Actions https://github.com/python/cpython/actions
Projects 31 https://github.com/python/cpython/projects
Security Uh oh! There was an error while loading. Please reload this page. https://github.com/python/cpython/security
Please reload this pagehttps://github.com/python/cpython/issues/127012
Insights https://github.com/python/cpython/pulse
Code https://github.com/python/cpython
Issues https://github.com/python/cpython/issues
Pull requests https://github.com/python/cpython/pulls
Actions https://github.com/python/cpython/actions
Projects https://github.com/python/cpython/projects
Security https://github.com/python/cpython/security
Insights https://github.com/python/cpython/pulse
New issuehttps://github.com/login?return_to=https://github.com/python/cpython/issues/127012
New issuehttps://github.com/login?return_to=https://github.com/python/cpython/issues/127012
python/importlib_resources#321https://github.com/python/importlib_resources/pull/321
importlib.abc.Traversable.read_text() incompatible with importlib.resources._functional.read_text() usage (Python 3.13)https://github.com/python/cpython/issues/127012#top
python/importlib_resources#321https://github.com/python/importlib_resources/pull/321
https://github.com/kurtmckee
https://github.com/jaraco
stdlibStandard Library Python modules in the Lib/ directoryhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22stdlib%22
topic-importlibhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22topic-importlib%22
type-bugAn unexpected behavior, bug, or errorhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22type-bug%22
https://github.com/kurtmckee
https://github.com/kurtmckee
kurtmckeehttps://github.com/kurtmckee
on Nov 19, 2024https://github.com/python/cpython/issues/127012#issue-2672194534
cpython/Lib/importlib/resources/abc.pyhttps://github.com/python/cpython/blob/30aeb00d367d0cc9e5a7603371636cddea09f1c0/Lib/importlib/resources/abc.py#L84-L90
30aeb00https://github.com/python/cpython/commit/30aeb00d367d0cc9e5a7603371636cddea09f1c0
cpython/Lib/importlib/resources/_functional.pyhttps://github.com/python/cpython/blob/30aeb00d367d0cc9e5a7603371636cddea09f1c0/Lib/importlib/resources/_functional.py#L28-L32
30aeb00https://github.com/python/cpython/commit/30aeb00d367d0cc9e5a7603371636cddea09f1c0
#88368https://github.com/python/cpython/issues/88368
jaracohttps://github.com/jaraco
kurtmckeehttps://github.com/kurtmckee
stdlibStandard Library Python modules in the Lib/ directoryhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22stdlib%22
topic-importlibhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22topic-importlib%22
type-bugAn unexpected behavior, bug, or errorhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22type-bug%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.