René's URL Explorer Experiment


Title: Fix: Correct handling of `import module as alias` in LPython semantic analysis by amritamishra01 · Pull Request #2872 · lcompilers/lpython · GitHub

Open Graph Title: Fix: Correct handling of `import module as alias` in LPython semantic analysis by amritamishra01 · Pull Request #2872 · lcompilers/lpython

X Title: Fix: Correct handling of `import module as alias` in LPython semantic analysis by amritamishra01 · Pull Request #2872 · lcompilers/lpython

Description: Summary This PR fixes an issue where import statements with aliases (e.g., import numpy as np) would load the module correctly but fail to register the alias (np) in the current scope. As a result, subsequent code using the alias (like np.array()) would fail with NameError: 'np' is not defined. This patch updates the semantic analysis phase to ensure import aliases are correctly created and installed into the symbol table as ExternalSymbols. Technical Changes Modified visit_Import in src/lpython/semantics/python_ast_to_asr.cpp: Refactored the logic to merge module name extraction and module loading into a single loop. Previously, these were handled in separate loops, causing the alias information (x.m_names[i].m_asname) to be lost before the symbol registration step. Implemented Alias Registration: Added logic to check for the presence of an alias. If an alias exists, the compiler now creates an ASR::ExternalSymbol_t in the current scope. This symbol maps the alias name (e.g., np) to the loaded module symbol (e.g., numpy), mirroring Python's behavior. Verification I verified the fix using the following reproduction script repro.py: import numpy as np print(np.array([1, 2, 3])) Before Fix: Compiling failed with: semantic error: NameError: 'np' is not defined After Fix: The compiler successfully resolves the alias. Running with --show-asr confirms the creation of the ExternalSymbol: np: (ExternalSymbol 2 np 1 numpy numpy [] numpy Public ) Fixes #2814

Open Graph Description: Summary This PR fixes an issue where import statements with aliases (e.g., import numpy as np) would load the module correctly but fail to register the alias (np) in the current scope. As a result,...

X Description: Summary This PR fixes an issue where import statements with aliases (e.g., import numpy as np) would load the module correctly but fail to register the alias (np) in the current scope. As a result,...

Opengraph URL: https://github.com/lcompilers/lpython/pull/2872

X: @github

direct link

Domain: patch-diff.githubusercontent.com

route-pattern/:user_id/:repository/pull/:id/checks(.:format)
route-controllerpull_requests
route-actionchecks
fetch-noncev2:52ddc961-596c-9509-9722-9ff4f8e643b6
current-catalog-service-hash87dc3bc62d9b466312751bfd5f889726f4f1337bdff4e8be7da7c93d6c00a25a
request-idD848:F6370:44C998D:5E60021:6977F75C
html-safe-nonce7af110a77a0dd8412be29de45e209ef0c157e0c150c976b58f0541738678a4b8
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEODQ4OkY2MzcwOjQ0Qzk5OEQ6NUU2MDAyMTo2OTc3Rjc1QyIsInZpc2l0b3JfaWQiOiIzNDk1NjY1NDQwMDc4MTY1ODUyIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0=
visitor-hmac317f24e5f9971a27c6fa81b066631111ff96e2cdf82fc7ea17ea9b632bf8375a
hovercard-subject-tagpull_request:3078136980
github-keyboard-shortcutsrepository,pull-request-list,pull-request-conversation,pull-request-files-changed,checks,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///pull_requests/show/checks
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/lcompilers/lpython/pull/2872/checks
twitter:imagehttps://avatars.githubusercontent.com/u/171616930?s=400&v=4
twitter:cardsummary_large_image
og:imagehttps://avatars.githubusercontent.com/u/171616930?s=400&v=4
og:image:altSummary This PR fixes an issue where import statements with aliases (e.g., import numpy as np) would load the module correctly but fail to register the alias (np) in the current scope. As a result,...
og:site_nameGitHub
og:typeobject
hostnamegithub.com
expected-hostnamegithub.com
None9306bf4a8c8a88a5945f83e25033fc5e6fb7a05f40c5fca300ac67db7fee56ae
turbo-cache-controlno-cache
go-importgithub.com/lcompilers/lpython git https://github.com/lcompilers/lpython.git
octolytics-dimension-user_id96538276
octolytics-dimension-user_loginlcompilers
octolytics-dimension-repository_id442864346
octolytics-dimension-repository_nwolcompilers/lpython
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id442864346
octolytics-dimension-repository_network_root_nwolcompilers/lpython
turbo-body-classeslogged-out env-production page-responsive full-width full-width-p-0
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
releasec586ac0f2edbf5b31f9ca03622220a4285e2def8
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://patch-diff.githubusercontent.com/lcompilers/lpython/pull/2872/checks#start-of-content
https://patch-diff.githubusercontent.com/
Sign in https://patch-diff.githubusercontent.com/login?return_to=https%3A%2F%2Fgithub.com%2Flcompilers%2Flpython%2Fpull%2F2872%2Fchecks
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://patch-diff.githubusercontent.com/login?return_to=https%3A%2F%2Fgithub.com%2Flcompilers%2Flpython%2Fpull%2F2872%2Fchecks
Sign up https://patch-diff.githubusercontent.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fpull_requests%2Fshow%2Fchecks&source=header-repo&source_repo=lcompilers%2Flpython
Reloadhttps://patch-diff.githubusercontent.com/lcompilers/lpython/pull/2872/checks
Reloadhttps://patch-diff.githubusercontent.com/lcompilers/lpython/pull/2872/checks
Reloadhttps://patch-diff.githubusercontent.com/lcompilers/lpython/pull/2872/checks
lcompilers https://patch-diff.githubusercontent.com/lcompilers
lpythonhttps://patch-diff.githubusercontent.com/lcompilers/lpython
Notifications https://patch-diff.githubusercontent.com/login?return_to=%2Flcompilers%2Flpython
Fork 173 https://patch-diff.githubusercontent.com/login?return_to=%2Flcompilers%2Flpython
Star 1.6k https://patch-diff.githubusercontent.com/login?return_to=%2Flcompilers%2Flpython
Code https://patch-diff.githubusercontent.com/lcompilers/lpython
Issues 503 https://patch-diff.githubusercontent.com/lcompilers/lpython/issues
Pull requests 85 https://patch-diff.githubusercontent.com/lcompilers/lpython/pulls
Actions https://patch-diff.githubusercontent.com/lcompilers/lpython/actions
Projects 0 https://patch-diff.githubusercontent.com/lcompilers/lpython/projects
Wiki https://patch-diff.githubusercontent.com/lcompilers/lpython/wiki
Security 0 https://patch-diff.githubusercontent.com/lcompilers/lpython/security
Insights https://patch-diff.githubusercontent.com/lcompilers/lpython/pulse
Code https://patch-diff.githubusercontent.com/lcompilers/lpython
Issues https://patch-diff.githubusercontent.com/lcompilers/lpython/issues
Pull requests https://patch-diff.githubusercontent.com/lcompilers/lpython/pulls
Actions https://patch-diff.githubusercontent.com/lcompilers/lpython/actions
Projects https://patch-diff.githubusercontent.com/lcompilers/lpython/projects
Wiki https://patch-diff.githubusercontent.com/lcompilers/lpython/wiki
Security https://patch-diff.githubusercontent.com/lcompilers/lpython/security
Insights https://patch-diff.githubusercontent.com/lcompilers/lpython/pulse
Sign up for GitHub https://patch-diff.githubusercontent.com/signup?return_to=%2Flcompilers%2Flpython%2Fissues%2Fnew%2Fchoose
terms of servicehttps://docs.github.com/terms
privacy statementhttps://docs.github.com/privacy
Sign inhttps://patch-diff.githubusercontent.com/login?return_to=%2Flcompilers%2Flpython%2Fissues%2Fnew%2Fchoose
amritamishra01https://patch-diff.githubusercontent.com/amritamishra01
lcompilers:mainhttps://patch-diff.githubusercontent.com/lcompilers/lpython/tree/main
amritamishra01:fix/import-aliashttps://patch-diff.githubusercontent.com/amritamishra01/lpython/tree/fix/import-alias
Conversation 2 https://patch-diff.githubusercontent.com/lcompilers/lpython/pull/2872
Commits 6 https://patch-diff.githubusercontent.com/lcompilers/lpython/pull/2872/commits
Checks 18 https://patch-diff.githubusercontent.com/lcompilers/lpython/pull/2872/checks
Files changed https://patch-diff.githubusercontent.com/lcompilers/lpython/pull/2872/files
Please reload this pagehttps://patch-diff.githubusercontent.com/lcompilers/lpython/pull/2872/checks
Please reload this pagehttps://patch-diff.githubusercontent.com/lcompilers/lpython/pull/2872/checks
Sign in for the full log viewhttps://patch-diff.githubusercontent.com/login?return_to=https%3A%2F%2Fgithub.com%2Flcompilers%2Flpython%2Fpull%2F2872%2Fchecks
Fix: Correct handling of import module as alias in LPython semantic analysis https://patch-diff.githubusercontent.com/lcompilers/lpython/pull/2872/checks#top
Please reload this pagehttps://patch-diff.githubusercontent.com/lcompilers/lpython/pull/2872/checks
LPython CI on: pull_request https://patch-diff.githubusercontent.com/lcompilers/lpython/actions/runs/20134179349
LPython CI (3.10, ubuntu-latest) https://patch-diff.githubusercontent.com/lcompilers/lpython/actions/runs/20134179349/job/57782945143?pr=2872
LPython CI (3.10, macos-latest) https://patch-diff.githubusercontent.com/lcompilers/lpython/actions/runs/20134179349/job/57782945133?pr=2872
LPython CI (3.10, windows-2025) https://patch-diff.githubusercontent.com/lcompilers/lpython/actions/runs/20134179349/job/57782945177?pr=2872
Build LPython to WASM https://patch-diff.githubusercontent.com/lcompilers/lpython/actions/runs/20134179349/job/57782945166?pr=2872
Test PIP Installable Packages https://patch-diff.githubusercontent.com/lcompilers/lpython/actions/runs/20134179349/job/57782945126?pr=2872
Check Debug build https://patch-diff.githubusercontent.com/lcompilers/lpython/actions/runs/20134179349/job/57782945125?pr=2872
Check Release build https://patch-diff.githubusercontent.com/lcompilers/lpython/actions/runs/20134179349/job/57782945144?pr=2872
Test CPython Interop (@pythoncall) https://patch-diff.githubusercontent.com/lcompilers/lpython/actions/runs/20134179349/job/57782945137?pr=2872
Run SymPy tests https://patch-diff.githubusercontent.com/lcompilers/lpython/actions/runs/20134179349/job/57782945154?pr=2872
Run Integration tests with Python 3.9 https://patch-diff.githubusercontent.com/lcompilers/lpython/actions/runs/20134179349/job/57782945176?pr=2872
Run Integration tests with Python 3.10 https://patch-diff.githubusercontent.com/lcompilers/lpython/actions/runs/20134179349/job/57782945215?pr=2872
Run Integration tests with Python 3.11 https://patch-diff.githubusercontent.com/lcompilers/lpython/actions/runs/20134179349/job/57782945164?pr=2872
Run Integration tests with Python 3.12 https://patch-diff.githubusercontent.com/lcompilers/lpython/actions/runs/20134179349/job/57782945193?pr=2872
Test LLVM 10 https://patch-diff.githubusercontent.com/lcompilers/lpython/actions/runs/20134179349/job/57782945167?pr=2872
Test LLVM 15 https://patch-diff.githubusercontent.com/lcompilers/lpython/actions/runs/20134179349/job/57782945179?pr=2872
Test LLVM 16 https://patch-diff.githubusercontent.com/lcompilers/lpython/actions/runs/20134179349/job/57782945153?pr=2872
Build Jupyter Kernel https://patch-diff.githubusercontent.com/lcompilers/lpython/actions/runs/20134179349/job/57782945152?pr=2872
Upload Tarball https://patch-diff.githubusercontent.com/lcompilers/lpython/actions/runs/20134179349/job/57782945139?pr=2872
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.