René's URL Explorer Experiment


Title: Running doctest examples on a class results in OSError in REPL · Issue #113329 · python/cpython · GitHub

Open Graph Title: Running doctest examples on a class results in OSError in REPL · Issue #113329 · python/cpython

X Title: Running doctest examples on a class results in OSError in REPL · Issue #113329 · python/cpython

Description: Bug report Bug description: In the REPL, running doctests contained in the docstring of a class is broken since version 3.10. Example: import doctest class A: """Docstring of A, with tests. >>> 1 + 2 3 """ pass doctest.run_docstring_exam...

Open Graph Description: Bug report Bug description: In the REPL, running doctests contained in the docstring of a class is broken since version 3.10. Example: import doctest class A: """Docstring of A, with tests. >>> 1 +...

X Description: Bug report Bug description: In the REPL, running doctests contained in the docstring of a class is broken since version 3.10. Example: import doctest class A: """Docstring of A, with...

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

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Running doctest examples on a class results in OSError in REPL","articleBody":"# Bug report\n\n### Bug description:\n\nIn the REPL, running doctests contained in the docstring of a class is broken since version 3.10. Example:\n\n```python\nimport doctest\n\nclass A:\n    \"\"\"Docstring of A, with tests.\n    >>> 1 + 2\n    3\n    \"\"\"\n    pass\n\ndoctest.run_docstring_examples(A, globals(), name='A', verbose=True)\n```\n\nIn version 3.9, this code works and executes the doctest in the docstring of the class `A`. In version 3.10 (and onward), the call to `doctest.run_docstring_examples` fails with `OSError: source code not available`.\n\nThis only fails in the REPL and not in regular Python files. In particular, this also fails in (Jupyter) notebook environments.\n\n### Cause\nThis change in behavior is caused by https://github.com/python/cpython/commit/48a62559dfaf775e4f1cc56b19379c799e8e2587 as a fix for #88814. Previously, `inspect.getsourcefile()` could only fail with `TypeError`, but this can now also be `OSError`. The new exception type is not being handled by doctest, only `TypeError` is caught: https://github.com/python/cpython/blob/713e42822f5c74d8420f641968c3bef4b10a513a/Lib/doctest.py#L924-L927\n\nThe call to `inspect.getsourcefile()` is only used by doctest to determine line numbers, if available. Thus, failing to find the source file can safely fail silently in environments where line numbers are not available (such as the REPL). \n\n### Proposed changes\n- Also catch `OSError` in the doctest finder (in the linked snippet).\n- Update the documentation to reflect that `inspect.getsourcefile()` can also fail with `OSError`.\n\nAn alternative would be to change the exception type in https://github.com/python/cpython/commit/48a62559dfaf775e4f1cc56b19379c799e8e2587 to also be `TypeError` in the case the source file is not available. I do not think this a desired change.\n\nI am happy to contribute a pull request with these changes.\n\n### CPython versions tested on:\n\n3.9, 3.10, 3.11\n\n### Operating systems tested on:\n\nLinux\n\n\u003c!-- gh-linked-prs -->\n### Linked PRs\n* gh-113335\n* gh-155658\n* gh-155659\n* gh-155660\n\u003c!-- /gh-linked-prs -->\n","author":{"url":"https://github.com/stenwessel","@type":"Person","name":"stenwessel"},"datePublished":"2023-12-20T20:11:01Z","url":"https://github.com/python/cpython/issues/113329"}

react-profiling0
react-import-mapreact,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322
route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:f0d4f10c-2886-9760-d2a5-80d74a4bb4c3
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-id93E6:299992:1922108:212B3AF:6B020F64
html-safe-nonce9c80b82a6efefd09af6f0f73dec23f44fe8df15c87b307b7b2669d0010460c7c
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5M0U2OjI5OTk5MjoxOTIyMTA4OjIxMkIzQUY6NkIwMjBGNjQiLCJ2aXNpdG9yX2lkIjoiMzc3NTU0NTE0MTQwNjg2MzIwNCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9
visitor-hmacebe68b95eca17c3c5432a83c78c57f58b100a0a9aa9f6c6d5926748d1719750e
hovercard-subject-tagissue:2051196127
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/113329/issue_layout
twitter:imagehttps://opengraph.githubassets.com/6412c3554d48f30f4843ed91272ac41c8767a1e32d7ec471229d0f906065ba76/python/cpython/issues/113329
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/6412c3554d48f30f4843ed91272ac41c8767a1e32d7ec471229d0f906065ba76/python/cpython/issues/113329
og:image:altBug report Bug description: In the REPL, running doctests contained in the docstring of a class is broken since version 3.10. Example: import doctest class A: """Docstring of A, with tests. >>> 1 +...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernamestenwessel
hostnamegithub.com
expected-hostnamegithub.com
None87e774ee7c6b3bee0490394e4d3e57ec9dbc956f74b87ea685dc8996c1676456
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
release423dbb54c5e7bfecc838eb387c1435eb3d0e760d
ui-targetfull
theme-color#1e2327
color-schemelight dark
react-app-nameissues

Links:

Skip to contenthttps://github.com/python/cpython/issues/113329#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fissues%2F113329
GitHubRepository hosting, code review, and collaborationhttps://github.com/platform
CopilotAI coding agent for tasks, projects, and automated workhttps://github.com/features/copilot
ActionsCI/CD and automationhttps://github.com/features/actions
Code QualityQuality analysis, fixes, and enforcementhttps://github.com/features/code-quality
CodespacesCloud development environmentshttps://github.com/features/codespaces
Code SecurityVulnerability detection and remediationhttps://github.com/security/advanced-security/code-security
Secret ProtectionSecret scanning and leak preventionhttps://github.com/security/advanced-security/secret-protection
All Featureshttps://github.com/features
Documentationhttps://docs.github.com/en
Traininghttps://learn.github.com/skills
Certificationshttps://learn.github.com/credentials
Build with Copilothttps://github.com/features/ai
Customize Copilothttps://docs.github.com/en/copilot/how-tos/copilot-on-github/customize-copilot/customize-copilot-overview
Integrationshttps://github.com/marketplace
Trending reposhttps://github.com/trending
GitHub Sponsorshttps://github.com/open-source/sponsors
Developer articleshttps://github.com/resources/articles
ChangelogYour source for the latest features, improvements, and fixes across GitHub products, all in one place.https://github.blog/changelog/
Enterpriseshttps://github.com/enterprise
Teamhttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
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
See all industrieshttps://github.com/solutions/industry
Why GitHubhttps://github.com/why-github
Customer Storieshttps://github.com/customer-stories
Business insightshttps://github.com/solutions/executive-insights
Trust Centerhttps://github.com/trust-center
GitHub Advanced SecurityEnterprise-grade code securityhttps://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/enterprise/premium-support
Documentationhttps://docs.github.com/en
Resource centerhttps://github.com/resources
Bloghttps://github.blog/
Events & webinarshttps://github.com/resources/events
Community Forumhttps://github.com/orgs/community/discussions
Customer Storieshttps://github.com/customer-stories
Integrationshttps://github.com/marketplace
Customer supporthttps://help.github.com/
Traininghttps://learn.github.com/skills
GitHub Statushttps://www.githubstatus.com/
Abouthttps://github.com/about
Partnershttps://github.com/partners
Changeloghttps://github.blog/changelog/
GitHub UniverseThe event for developers, by developers — talks, workshops, and what’s next for GitHub.https://githubuniverse.com/
Pricinghttps://github.com/pricing
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fissues%2F113329
Sign uphttps://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/113329
Reloadhttps://github.com/python/cpython/issues/113329
Reloadhttps://github.com/python/cpython/issues/113329
pythonhttps://github.com/python
cpythonhttps://github.com/python/cpython
Codehttps://github.com/python/cpython
Issues5k+ (5k+)https://github.com/python/cpython/issues
Pull requests2.4k (2.4k)https://github.com/python/cpython/pulls
Actionshttps://github.com/python/cpython/actions
Projectshttps://github.com/python/cpython/projects
Security and qualityhttps://github.com/python/cpython/security
Insightshttps://github.com/python/cpython/insights
https://github.com/python/cpython
New issuehttps://github.com/login?return_to=https://github.com/python/cpython/issues/113329
New issuehttps://github.com/login?return_to=https://github.com/python/cpython/issues/113329
#113335https://github.com/python/cpython/pull/113335
Running doctest examples on a class results in OSError in REPLhttps://github.com/python/cpython/issues/113329#top
#113335https://github.com/python/cpython/pull/113335
3.13only security fixeshttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%223.13%22
3.14bugs and security fixeshttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%223.14%22
3.15bugs and security fixeshttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%223.15%22
3.16new features, bugs and security fixeshttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%223.16%22
stdlibStandard Library Python modules in the Lib/ directoryhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22stdlib%22
topic-replRelated to the interactive shellhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22topic-repl%22
type-bugAn unexpected behavior, bug, or errorhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22type-bug%22
https://github.com/stenwessel
stenwesselhttps://github.com/stenwessel
on Dec 20, 2023https://github.com/python/cpython/issues/113329#issue-2051196127
48a6255https://github.com/python/cpython/commit/48a62559dfaf775e4f1cc56b19379c799e8e2587
#88814https://github.com/python/cpython/issues/88814
cpython/Lib/doctest.pyhttps://github.com/python/cpython/blob/713e42822f5c74d8420f641968c3bef4b10a513a/Lib/doctest.py#L924-L927
713e428https://github.com/python/cpython/commit/713e42822f5c74d8420f641968c3bef4b10a513a
48a6255https://github.com/python/cpython/commit/48a62559dfaf775e4f1cc56b19379c799e8e2587
gh-113329: Catch OSError in doctest finder and document that inspect.getsourcefile/getfile can raise OSError #113335https://github.com/python/cpython/pull/113335
[3.15] gh-113329: Catch OSError in doctest finder and document that inspect.getsourcefile/getfile can raise OSError (GH-113335) #155658https://github.com/python/cpython/pull/155658
[3.14] gh-113329: Catch OSError in doctest finder and document that inspect.getsourcefile/getfile can raise OSError (GH-113335) #155659https://github.com/python/cpython/pull/155659
[3.13] gh-113329: Catch OSError in doctest finder and document that inspect.getsourcefile/getfile can raise OSError (GH-113335) #155660https://github.com/python/cpython/pull/155660
stenwesselhttps://github.com/stenwessel
type-bugAn unexpected behavior, bug, or errorhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22type-bug%22
on Dec 20, 2023https://github.com/python/cpython/issues/113329#event-11306998255
AlexWaygoodhttps://github.com/AlexWaygood
stdlibStandard Library Python modules in the Lib/ directoryhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22stdlib%22
3.11only security fixeshttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%223.11%22
3.12only security fixeshttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%223.12%22
3.13only security fixeshttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%223.13%22
on Dec 20, 2023https://github.com/python/cpython/issues/113329#event-11307059813
https://github.com/gaogaotiantian
gaogaotiantianhttps://github.com/gaogaotiantian
on Dec 20, 2023https://github.com/python/cpython/issues/113329#issuecomment-1865186597
inspect.getsourcelineshttps://docs.python.org/3/library/inspect.html#inspect.getsourcelines
stenwesselhttps://github.com/stenwessel
on Dec 20, 2023https://github.com/python/cpython/issues/113329#event-11307797170
pythongh-113329: Catch OSError in doctest finderhttps://github.com/stenwessel/cpython/commit/45e1a93cd282ba2e4969dfafab828ed00c24311a
pythongh-113329https://github.com/python/cpython/issues/113329
45e1a93https://github.com/stenwessel/cpython/commit/45e1a93cd282ba2e4969dfafab828ed00c24311a
Merge branch 'main' into pythongh-113329https://github.com/stenwessel/cpython/commit/b9f14773156383e64be0f61fd892e7bf811b04f7
pythongh-113329https://github.com/python/cpython/issues/113329
b9f1477https://github.com/stenwessel/cpython/commit/b9f14773156383e64be0f61fd892e7bf811b04f7
https://github.com/serhiy-storchaka
serhiy-storchakahttps://github.com/serhiy-storchaka
on Dec 22, 2023https://github.com/python/cpython/issues/113329#issuecomment-1867429730
@stenwesselhttps://github.com/stenwessel
https://github.com/serhiy-storchaka
serhiy-storchakahttps://github.com/serhiy-storchaka
on Dec 22, 2023https://github.com/python/cpython/issues/113329#issuecomment-1867431123
@ambvhttps://github.com/ambv
https://github.com/stenwessel
stenwesselhttps://github.com/stenwessel
on Dec 22, 2023https://github.com/python/cpython/issues/113329#issuecomment-1867536889
@serhiy-storchakahttps://github.com/serhiy-storchaka
AlexWaygoodhttps://github.com/AlexWaygood
topic-replRelated to the interactive shellhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22topic-repl%22
on May 10, 2024https://github.com/python/cpython/issues/113329#event-12768823024
https://github.com/mforbes
mforbeshttps://github.com/mforbes
on Aug 19, 2025https://github.com/python/cpython/issues/113329#issuecomment-3201746026
pythonhttps://github.com/python
https://github.com/undefined
on Oct 14, 2025https://github.com/python/cpython/issues/113329#event-20278352481
serhiy-storchakahttps://github.com/serhiy-storchaka
3.14bugs and security fixeshttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%223.14%22
3.15bugs and security fixeshttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%223.15%22
3.16new features, bugs and security fixeshttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%223.16%22
3.11only security fixeshttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%223.11%22
3.12only security fixeshttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%223.12%22
on Aug 13, 2026https://github.com/python/cpython/issues/113329#event-29385709581
serhiy-storchakahttps://github.com/serhiy-storchaka
on Aug 13, 2026https://github.com/python/cpython/issues/113329#event-29386268430
gh-113329: Catch OSError in doctest finder and document that inspect.…https://github.com/python/cpython/commit/025e7d278e29f3df2e95ed9daf9d9835760564c8
gh-113329https://github.com/python/cpython/issues/113329
025e7d2https://github.com/python/cpython/commit/025e7d278e29f3df2e95ed9daf9d9835760564c8
serhiy-storchakahttps://github.com/serhiy-storchaka
completedhttps://github.com/python/cpython/issues?q=is%3Aissue%20state%3Aclosed%20archived%3Afalse%20reason%3Acompleted
#113335https://github.com/python/cpython/pull/113335
on Aug 13, 2026https://github.com/python/cpython/issues/113329#event-29386268535
serhiy-storchakahttps://github.com/serhiy-storchaka
on Aug 13, 2026https://github.com/python/cpython/issues/113329#event-29390953323
[3.14] gh-113329: Catch OSError in doctest finder and document that i…https://github.com/python/cpython/commit/ed58355414485d37441d1df1eed5b799851bd8b8
gh-113329https://github.com/python/cpython/issues/113329
ed58355https://github.com/python/cpython/commit/ed58355414485d37441d1df1eed5b799851bd8b8
[3.13] gh-113329: Catch OSError in doctest finder and document that i…https://github.com/python/cpython/commit/4fe54900ddebf20e4d509b484656361f03a8df2e
gh-113329https://github.com/python/cpython/issues/113329
4fe5490https://github.com/python/cpython/commit/4fe54900ddebf20e4d509b484656361f03a8df2e
hugovkhttps://github.com/hugovk
on Aug 14, 2026https://github.com/python/cpython/issues/113329#event-29448258458
[3.15] gh-113329: Catch OSError in doctest finder and document that i…https://github.com/python/cpython/commit/791f38c886426549c30f41db0008e84562da5149
gh-113329https://github.com/python/cpython/issues/113329
791f38chttps://github.com/python/cpython/commit/791f38c886426549c30f41db0008e84562da5149
mbeijenhttps://github.com/mbeijen
on Aug 14, 2026https://github.com/python/cpython/issues/113329#event-29455508885
pythongh-113329: Catch OSError in doctest finder and document that in…https://github.com/mbeijen/cpython/commit/ff71ce7311e8587158f5344d60c8f6d6259e377d
pythongh-113329https://github.com/python/cpython/issues/113329
ff71ce7https://github.com/mbeijen/cpython/commit/ff71ce7311e8587158f5344d60c8f6d6259e377d
Sign up for freehttps://github.com/signup?return_to=https://github.com/python/cpython/issues/113329
Sign in to commenthttps://github.com/login?return_to=https://github.com/python/cpython/issues/113329
3.13only security fixeshttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%223.13%22
3.14bugs and security fixeshttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%223.14%22
3.15bugs and security fixeshttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%223.15%22
3.16new features, bugs and security fixeshttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%223.16%22
stdlibStandard Library Python modules in the Lib/ directoryhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22stdlib%22
topic-replRelated to the interactive shellhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22topic-repl%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.