René's URL Explorer Experiment


Title: fix(graph_search): avoid KeyError in BFS when a node has no outgoing edges by Saadanjum0 · Pull Request #506 · faif/python-patterns · GitHub

Open Graph Title: fix(graph_search): avoid KeyError in BFS when a node has no outgoing edges by Saadanjum0 · Pull Request #506 · faif/python-patterns

X Title: fix(graph_search): avoid KeyError in BFS when a node has no outgoing edges by Saadanjum0 · Pull Request #506 · faif/python-patterns

Description: find_shortest_path_bfs indexed self.graph[value] directly while expanding the BFS queue. Any node that is reachable in the graph but is not present as a dict key — a leaf node with no outgoing edges, which is normal for an adjacency-list graph — raised a KeyError instead of being treated as having no neighbors. The other traversal methods on this class (find_path_dfs, find_all_paths_dfs, find_shortest_path_dfs) already handle this correctly via self.graph.get(start, []). This brings find_shortest_path_bfs in line with them. Repro before the fix: graph = {"A": ["B"], "B": ["C", "D"]} # C and D are leaf nodes, no key in graph GraphSearch(graph).find_shortest_path_bfs("A", "Z") # KeyError: 'D' Added a regression test (tests/test_graph_search.py) that fails before this change and passes after. Ran the full suite locally with the new test passing. Also ran codespell, flake8, isort, black --check, and mypy on the changed files with no issues.

Open Graph Description: find_shortest_path_bfs indexed self.graph[value] directly while expanding the BFS queue. Any node that is reachable in the graph but is not present as a dict key — a leaf node with no outgoing edge...

X Description: find_shortest_path_bfs indexed self.graph[value] directly while expanding the BFS queue. Any node that is reachable in the graph but is not present as a dict key — a leaf node with no outgoing edge...

Opengraph URL: https://github.com/faif/python-patterns/pull/506

X: @github

direct link

Domain: github.com

react-profiling0
react-import-mapreact,react-dom,react-dom/client,react-dom/profiling,react-is,react-reconciler,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@d5750093facf
route-pattern/:user_id/:repository/pull/:id/files(.:format)
route-controllerpull_requests
route-actionfiles
fetch-noncev2:ce1080d2-985b-51e5-a49e-b53d59255d5a
current-catalog-service-hashae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b
request-idBA50:CE688:132F73:1AA54A:6AFB7766
html-safe-noncec98c6281d7d0c5392b60db7e065a9690171107080ea35384e9e474002a03920e
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCQTUwOkNFNjg4OjEzMkY3MzoxQUE1NEE6NkFGQjc3NjYiLCJ2aXNpdG9yX2lkIjoiMTc5NjQ3NTQ4NDcyOTIxMDcyNiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9
visitor-hmac3107a83976135d86549bdb27673076d7bbcf678645c9ed7368bfd65b69dedb7a
hovercard-subject-tagpull_request:4797969279
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/faif/python-patterns/pull/506/files
twitter:imagehttps://avatars.githubusercontent.com/u/160885369?s=400&v=4
twitter:cardsummary_large_image
og:imagehttps://avatars.githubusercontent.com/u/160885369?s=400&v=4
og:image:altfind_shortest_path_bfs indexed self.graph[value] directly while expanding the BFS queue. Any node that is reachable in the graph but is not present as a dict key — a leaf node with no outgoing edge...
og:site_nameGitHub
og:typeobject
hostnamegithub.com
expected-hostnamegithub.com
None0e29e7974fdda2feeaf5c891efd4b23b0734b23480232b62c7bdef13f40b5b48
turbo-cache-controlno-preview
diff-viewunified
go-importgithub.com/faif/python-patterns git https://github.com/faif/python-patterns.git
octolytics-dimension-user_id1304661
octolytics-dimension-user_loginfaif
octolytics-dimension-repository_id4578002
octolytics-dimension-repository_nwofaif/python-patterns
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id4578002
octolytics-dimension-repository_network_root_nwofaif/python-patterns
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
release2e8872b770cc4d5d0cc1f2026afab747a268e2ce
ui-targetcanary-2
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/faif/python-patterns/pull/506/files#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Ffaif%2Fpython-patterns%2Fpull%2F506%2Ffiles
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%2Ffaif%2Fpython-patterns%2Fpull%2F506%2Ffiles
Sign uphttps://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=faif%2Fpython-patterns
Reloadhttps://github.com/faif/python-patterns/pull/506/files
Reloadhttps://github.com/faif/python-patterns/pull/506/files
Reloadhttps://github.com/faif/python-patterns/pull/506/files
faifhttps://github.com/faif
python-patternshttps://github.com/faif/python-patterns
Codehttps://github.com/faif/python-patterns
Issues9 (9)https://github.com/faif/python-patterns/issues
Pull requests3 (3)https://github.com/faif/python-patterns/pulls
Actionshttps://github.com/faif/python-patterns/actions
Projectshttps://github.com/faif/python-patterns/projects
Wikihttps://github.com/faif/python-patterns/wiki
Security and qualityhttps://github.com/faif/python-patterns/security
Insightshttps://github.com/faif/python-patterns/pulse
Sign up for GitHub https://github.com/signup?return_to=%2Ffaif%2Fpython-patterns%2Fissues%2Fnew%2Fchoose
terms of servicehttps://docs.github.com/terms
privacy statementhttps://docs.github.com/privacy
Sign inhttps://github.com/login?return_to=%2Ffaif%2Fpython-patterns%2Fissues%2Fnew%2Fchoose
faifhttps://github.com/faif
faif:masterhttps://github.com/faif/python-patterns/tree/master
Saadanjum0:fix/graph-search-bfs-keyerrorhttps://github.com/Saadanjum0/python-patterns/tree/fix/graph-search-bfs-keyerror
Conversation 0 https://github.com/faif/python-patterns/pull/506
Commits 1 https://github.com/faif/python-patterns/pull/506/commits
Checks 6 https://github.com/faif/python-patterns/pull/506/checks
Files changed https://github.com/faif/python-patterns/pull/506/files
Please reload this pagehttps://github.com/faif/python-patterns/pull/506/files
fix(graph_search): avoid KeyError in BFS when a node has no outgoing edges https://github.com/faif/python-patterns/pull/506/files#top
Show all changes 1 commit https://github.com/faif/python-patterns/pull/506/files
05f88ff fix(graph_search): avoid KeyError in BFS when a node has no outgoing … Saadanjum0 Oct 2, 2026 https://github.com/faif/python-patterns/pull/506/commits/05f88ff86fb3c1cb3a3ff04eeeb85026eb862124
Clear filters https://github.com/faif/python-patterns/pull/506/files
Please reload this pagehttps://github.com/faif/python-patterns/pull/506/files
Please reload this pagehttps://github.com/faif/python-patterns/pull/506/files
graph_search.py https://github.com/faif/python-patterns/pull/506/files#diff-6cba9c201bc949dab40ed97e2b197f9e4ed571074338900aa81d672a4d32bf71
test_graph_search.py https://github.com/faif/python-patterns/pull/506/files#diff-3ebcb8739a4ba80505ec1c8407dcb078f2531900c630bb35ed991942f2a6ba9f
patterns/other/graph_search.pyhttps://github.com/faif/python-patterns/pull/506/files#diff-6cba9c201bc949dab40ed97e2b197f9e4ed571074338900aa81d672a4d32bf71
View file https://github.com/Saadanjum0/python-patterns/blob/05f88ff86fb3c1cb3a3ff04eeeb85026eb862124/patterns/other/graph_search.py
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/faif/python-patterns/pull/506/{{ revealButtonHref }}
https://github.com/faif/python-patterns/pull/506/files#diff-6cba9c201bc949dab40ed97e2b197f9e4ed571074338900aa81d672a4d32bf71
https://github.com/faif/python-patterns/pull/506/files#diff-6cba9c201bc949dab40ed97e2b197f9e4ed571074338900aa81d672a4d32bf71
tests/test_graph_search.pyhttps://github.com/faif/python-patterns/pull/506/files#diff-3ebcb8739a4ba80505ec1c8407dcb078f2531900c630bb35ed991942f2a6ba9f
View file https://github.com/Saadanjum0/python-patterns/blob/05f88ff86fb3c1cb3a3ff04eeeb85026eb862124/tests/test_graph_search.py
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/faif/python-patterns/pull/506/{{ revealButtonHref }}
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.