René's URL Explorer Experiment


Title: module: honor module-level __dir__ (PEP 562) by JaceJung-dev · Pull Request #8271 · RustPython/RustPython · GitHub

Open Graph Title: module: honor module-level __dir__ (PEP 562) by JaceJung-dev · Pull Request #8271 · RustPython/RustPython

X Title: module: honor module-level __dir__ (PEP 562) by JaceJung-dev · Pull Request #8271 · RustPython/RustPython

Description: Closes #8231 This PR follows our AI policy Summary A module-level __dir__ function (PEP 562) was ignored: dir(module) returned the raw __dict__ keys instead of calling the module's __dir__. # mod.py def __dir__(): return ['gamma', 'alpha', 'beta'] # before: dir(mod) -> ['__builtins__', '__cached__', '__dir__', ...] # after: dir(mod) -> ['alpha', 'beta', 'gamma'] # matches CPython (dir() sorts) Cause PyModule::__dir__ (crates/vm/src/builtins/module.rs) unconditionally returned the module dict's keys, with no check for a module-level __dir__. Fix This ports the behavior of CPython's module_dir() in Objects/moduleobject.c, which is the reference implementation for this change: look up __dir__ in the module's __dict__ first and, if present, call it and return its result; otherwise fall back to list(__dict__). The lookup is a direct dict access, so neither the module-level __getattr__ nor the type's own __dir__ slot is involved. A non-callable or wrongly-signed __dir__ raises TypeError, matching CPython. The @unittest.expectedFailure # TODO: RUSTPYTHON markers on test_module_dir and test_module_dir_errors are removed since both now pass. Side effect Honoring a module-level __dir__ also fixes dir() for stdlib modules that define one, which flips two previously-failing tests to passing. Their stale @unittest.expectedFailure # TODO: RUSTPYTHON markers are removed as well (otherwise they would be reported as unexpected successes and fail CI): test_zoneinfo.test_dir_contains_all — zoneinfo.__dir__ makes dir(zoneinfo) contain everything in __all__. test_support.test_check__all__ — support.check__all__ iterates dir(module); unittest.__dir__ now surfaces IsolatedAsyncioTestCase (declared in unittest.__all__ but lazily loaded via PEP 562), so the check matches __all__. Test Verified locally: cargo run --release -- -m test test_module -v → SUCCESS (run=39) (test_module_dir / test_module_dir_errors ... ok) cargo run --release -- -m test test_zoneinfo → SUCCESS (test_dir_contains_all now passes) cargo run --release -- -m test test_support → SUCCESS (test_check__all__ now passes via dir(unittest)) cargo run --release -- -m test test_unittest test_concurrent_futures → SUCCESS (the other stdlib modules with a module-level __dir__; no regressions) Assisted-by: Claude Code:claude-opus-4-8 Summary by CodeRabbit New Features Modules can now define a custom __dir__ function to control the names returned when inspecting available attributes. Existing default behavior remains unchanged when no custom __dir__ is provided.

Open Graph Description: Closes #8231 This PR follows our AI policy Summary A module-level __dir__ function (PEP 562) was ignored: dir(module) returned the raw __dict__ keys instead of calling the module's __dir__. #...

X Description: Closes #8231 This PR follows our AI policy Summary A module-level __dir__ function (PEP 562) was ignored: dir(module) returned the raw __dict__ keys instead of calling the module's __dir_...

Opengraph URL: https://github.com/RustPython/RustPython/pull/8271

X: @github

direct link

Domain: github.com

route-pattern/:user_id/:repository/pull/:id/files(.:format)
route-controllerpull_requests
route-actionfiles
fetch-noncev2:730bd2d9-8602-ab0a-67ff-101824cc8a19
current-catalog-service-hashae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b
request-idB006:935FE:1265705:1A9F6CD:6A58BB70
html-safe-nonce50e120c6e804223bb4ba5e006000eeeea318eccd24e10fa9e9e471e6ac1826ec
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCMDA2OjkzNUZFOjEyNjU3MDU6MUE5RjZDRDo2QTU4QkI3MCIsInZpc2l0b3JfaWQiOiIxNTAxMzAxNzM5ODgyMDY4ODQ4IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0=
visitor-hmaca533f36ef160dec9d3de6d08f24eb55cf85a5770103e2605baef9c77f983b6ec
hovercard-subject-tagpull_request:4044572601
github-keyboard-shortcutsrepository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///pull_requests/show/files
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/RustPython/RustPython/pull/8271/files
twitter:imagehttps://avatars.githubusercontent.com/u/192051293?s=400&v=4
twitter:cardsummary_large_image
og:imagehttps://avatars.githubusercontent.com/u/192051293?s=400&v=4
og:image:altCloses #8231 This PR follows our AI policy Summary A module-level __dir__ function (PEP 562) was ignored: dir(module) returned the raw __dict__ keys instead of calling the module's __dir__. #...
og:site_nameGitHub
og:typeobject
hostnamegithub.com
expected-hostnamegithub.com
None5f2a0c7865178af3d91dd9f13b0cdfc3c73a2529c873d2780bb4c01271a57ec6
turbo-cache-controlno-preview
diff-viewunified
go-importgithub.com/RustPython/RustPython git https://github.com/RustPython/RustPython.git
octolytics-dimension-user_id39710557
octolytics-dimension-user_loginRustPython
octolytics-dimension-repository_id135201145
octolytics-dimension-repository_nwoRustPython/RustPython
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id135201145
octolytics-dimension-repository_network_root_nwoRustPython/RustPython
turbo-body-classeslogged-out env-production page-responsive full-width
disable-turbotrue
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release8aae7b8d6caacacf5c66eaeb2702d8dc88d85b4a
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/RustPython/RustPython/pull/8271/files#start-of-content
https://github.com/
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2FRustPython%2FRustPython%2Fpull%2F8271%2Ffiles
GitHub CopilotWrite better code with AIhttps://github.com/features/copilot
GitHub Copilot appDirect agents from issue to mergehttps://github.com/features/ai/github-app
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
View all resourceshttps://github.com/resources
GitHub SponsorsFund open source developershttps://github.com/open-source/sponsors
Security Labhttps://securitylab.github.com
Maintainer Communityhttps://maintainers.github.com
Acceleratorhttps://github.com/open-source/accelerator
GitHub Starshttps://stars.github.com
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/enterprise/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%2FRustPython%2FRustPython%2Fpull%2F8271%2Ffiles
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%2Fpull_requests%2Fshow%2Ffiles&source=header-repo&source_repo=RustPython%2FRustPython
Reloadhttps://github.com/RustPython/RustPython/pull/8271/files
Reloadhttps://github.com/RustPython/RustPython/pull/8271/files
Reloadhttps://github.com/RustPython/RustPython/pull/8271/files
Please reload this pagehttps://github.com/RustPython/RustPython/pull/8271/files
RustPython https://github.com/RustPython
RustPythonhttps://github.com/RustPython/RustPython
Notifications https://github.com/login?return_to=%2FRustPython%2FRustPython
Fork 1.5k https://github.com/login?return_to=%2FRustPython%2FRustPython
Star 22.2k https://github.com/login?return_to=%2FRustPython%2FRustPython
Code https://github.com/RustPython/RustPython
Issues 287 https://github.com/RustPython/RustPython/issues
Pull requests 101 https://github.com/RustPython/RustPython/pulls
Discussions https://github.com/RustPython/RustPython/discussions
Actions https://github.com/RustPython/RustPython/actions
Projects https://github.com/RustPython/RustPython/projects
Models https://github.com/RustPython/RustPython/models
Wiki https://github.com/RustPython/RustPython/wiki
Security and quality 0 https://github.com/RustPython/RustPython/security
Insights https://github.com/RustPython/RustPython/pulse
Code https://github.com/RustPython/RustPython
Issues https://github.com/RustPython/RustPython/issues
Pull requests https://github.com/RustPython/RustPython/pulls
Discussions https://github.com/RustPython/RustPython/discussions
Actions https://github.com/RustPython/RustPython/actions
Projects https://github.com/RustPython/RustPython/projects
Models https://github.com/RustPython/RustPython/models
Wiki https://github.com/RustPython/RustPython/wiki
Security and quality https://github.com/RustPython/RustPython/security
Insights https://github.com/RustPython/RustPython/pulse
Sign up for GitHub https://github.com/signup?return_to=%2FRustPython%2FRustPython%2Fissues%2Fnew%2Fchoose
terms of servicehttps://docs.github.com/terms
privacy statementhttps://docs.github.com/privacy
Sign inhttps://github.com/login?return_to=%2FRustPython%2FRustPython%2Fissues%2Fnew%2Fchoose
youknowonehttps://github.com/youknowone
RustPython:mainhttps://github.com/RustPython/RustPython/tree/main
JaceJung-dev:fix-module-dir-pep562https://github.com/JaceJung-dev/RustPython/tree/fix-module-dir-pep562
Conversation 3 https://github.com/RustPython/RustPython/pull/8271
Commits 3 https://github.com/RustPython/RustPython/pull/8271/commits
Checks 26 https://github.com/RustPython/RustPython/pull/8271/checks
Files changed 4 https://github.com/RustPython/RustPython/pull/8271/files
module: honor module-level __dir__ (PEP 562) https://github.com/RustPython/RustPython/pull/8271/files#top
Show all changes 3 commits https://github.com/RustPython/RustPython/pull/8271/files
3c64cb5 module: honor module-level __dir__ (PEP 562) JaceJung-dev Jul 13, 2026 https://github.com/RustPython/RustPython/pull/8271/commits/3c64cb5f7804254e186b83d80c8dc5a4096f384d
f70765a test: unmark zoneinfo test_dir_contains_all (PEP 562 __dir__) JaceJung-dev Jul 13, 2026 https://github.com/RustPython/RustPython/pull/8271/commits/f70765ae1c349706a7e36856cf8dbbe149d5df1d
b79f9df test: unmark test_support.test_check__all__ (PEP 562 __dir__) JaceJung-dev Jul 14, 2026 https://github.com/RustPython/RustPython/pull/8271/commits/b79f9df372be15adf7cf1773f19dfe89d1963259
Clear filters https://github.com/RustPython/RustPython/pull/8271/files
Please reload this pagehttps://github.com/RustPython/RustPython/pull/8271/files
Please reload this pagehttps://github.com/RustPython/RustPython/pull/8271/files
__init__.py https://github.com/RustPython/RustPython/pull/8271/files#diff-8650acd0d84aa122f5d0f3d5975d602dedb7fac645ed6dea24ea53e14be0021d
test_support.py https://github.com/RustPython/RustPython/pull/8271/files#diff-cb42fd26146ec61cb2242243494a9f314667a9a39153ad17e37465ff5a8a8000
test_zoneinfo.py https://github.com/RustPython/RustPython/pull/8271/files#diff-7908b1930bd1135d6f8077ef5ff578b02577f5f7042b54be88b9b86b6c7af45d
module.rs https://github.com/RustPython/RustPython/pull/8271/files#diff-1b1658fe8f1e6aa57ba5cb8b7f33a6c83dad6600554e0125c989aa083ea26a0e
Lib/test/test_module/__init__.pyhttps://github.com/RustPython/RustPython/pull/8271/files#diff-8650acd0d84aa122f5d0f3d5975d602dedb7fac645ed6dea24ea53e14be0021d
View file https://github.com/JaceJung-dev/RustPython/blob/b79f9df372be15adf7cf1773f19dfe89d1963259/Lib/test/test_module/__init__.py
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/RustPython/RustPython/pull/8271/{{ revealButtonHref }}
https://github.com/RustPython/RustPython/pull/8271/files#diff-8650acd0d84aa122f5d0f3d5975d602dedb7fac645ed6dea24ea53e14be0021d
https://github.com/RustPython/RustPython/pull/8271/files#diff-8650acd0d84aa122f5d0f3d5975d602dedb7fac645ed6dea24ea53e14be0021d
Lib/test/test_support.pyhttps://github.com/RustPython/RustPython/pull/8271/files#diff-cb42fd26146ec61cb2242243494a9f314667a9a39153ad17e37465ff5a8a8000
View file https://github.com/JaceJung-dev/RustPython/blob/b79f9df372be15adf7cf1773f19dfe89d1963259/Lib/test/test_support.py
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/RustPython/RustPython/pull/8271/{{ revealButtonHref }}
https://github.com/RustPython/RustPython/pull/8271/files#diff-cb42fd26146ec61cb2242243494a9f314667a9a39153ad17e37465ff5a8a8000
https://github.com/RustPython/RustPython/pull/8271/files#diff-cb42fd26146ec61cb2242243494a9f314667a9a39153ad17e37465ff5a8a8000
Lib/test/test_zoneinfo/test_zoneinfo.pyhttps://github.com/RustPython/RustPython/pull/8271/files#diff-7908b1930bd1135d6f8077ef5ff578b02577f5f7042b54be88b9b86b6c7af45d
View file https://github.com/JaceJung-dev/RustPython/blob/b79f9df372be15adf7cf1773f19dfe89d1963259/Lib/test/test_zoneinfo/test_zoneinfo.py
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/RustPython/RustPython/pull/8271/{{ revealButtonHref }}
https://github.com/RustPython/RustPython/pull/8271/files#diff-7908b1930bd1135d6f8077ef5ff578b02577f5f7042b54be88b9b86b6c7af45d
https://github.com/RustPython/RustPython/pull/8271/files#diff-7908b1930bd1135d6f8077ef5ff578b02577f5f7042b54be88b9b86b6c7af45d
crates/vm/src/builtins/module.rshttps://github.com/RustPython/RustPython/pull/8271/files#diff-1b1658fe8f1e6aa57ba5cb8b7f33a6c83dad6600554e0125c989aa083ea26a0e
View file https://github.com/JaceJung-dev/RustPython/blob/b79f9df372be15adf7cf1773f19dfe89d1963259/crates/vm/src/builtins/module.rs
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/RustPython/RustPython/pull/8271/{{ revealButtonHref }}
https://github.com/RustPython/RustPython/pull/8271/files#diff-1b1658fe8f1e6aa57ba5cb8b7f33a6c83dad6600554e0125c989aa083ea26a0e
https://github.com/RustPython/RustPython/pull/8271/files#diff-1b1658fe8f1e6aa57ba5cb8b7f33a6c83dad6600554e0125c989aa083ea26a0e
Please reload this pagehttps://github.com/RustPython/RustPython/pull/8271/files
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.