René's URL Explorer Experiment


Title: Conditional import of a class follows imports of all branches · Issue #19009 · python/mypy · GitHub

Open Graph Title: Conditional import of a class follows imports of all branches · Issue #19009 · python/mypy

X Title: Conditional import of a class follows imports of all branches · Issue #19009 · python/mypy

Description: Bug Report When you have the following provider module: if sys.platform == "win32": from my_pkg._pty.windows import PtySession else: from my_pkg._pty.unix import PtySession and attempt importing this symbol from somewhere else, Mypy does...

Open Graph Description: Bug Report When you have the following provider module: if sys.platform == "win32": from my_pkg._pty.windows import PtySession else: from my_pkg._pty.unix import PtySession and attempt importing th...

X Description: Bug Report When you have the following provider module: if sys.platform == "win32": from my_pkg._pty.windows import PtySession else: from my_pkg._pty.unix import PtySession and attempt im...

Opengraph URL: https://github.com/python/mypy/issues/19009

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Conditional import of a class follows imports of all branches","articleBody":"**Bug Report**\n\nWhen you have the following provider module:\n\n```python\nif sys.platform == \"win32\":\n    from my_pkg._pty.windows import PtySession\nelse:\n    from my_pkg._pty.unix import PtySession\n```\n\nand attempt importing this symbol from somewhere else, Mypy does not respect the platform condition.\n\nFor example, if you call `pty.openpty()` inside `my_pkg._pty.unix` and run Mypy on Windows it will show:\n\n```\nModule has no attribute \"openpty\"  [attr-defined]\n```\n\n**To Reproduce**\n\nCreate the following structure:\n\n```\nmypy-issue\n├── pyproject.toml\n└── pkg\n    ├── __init__.py\n    ├── main.py\n    └── _pty\n        ├── __init__.py\n        ├── interface.py\n        ├── session.py\n        ├── unix.py\n        └── windows.py\n```\n\nwith the following contents (`__init__.py` files are empty):\n\n\u003ctable>\n\u003ctr>\u003cth>\u003ccode>pyproject.toml\u003c/code>\u003c/th>\u003c/tr>\n\u003ctr>\u003ctd>\n\n```toml\n\n[tool.mypy]\npretty = true\n```\n\n\u003c/td>\u003c/tr>\u003c/table>\n\n\u003ctable>\n\u003ctr>\u003cth>\u003ccode>pkg/main.py\u003c/code>\u003c/th>\u003c/tr>\n\u003ctr>\u003ctd>\n\n```python\nfrom __future__ import annotations\n\n\nclass SubprocessRunner:\n    def run(self) -> bool:\n        from ._pty.session import PtySession\n\n        return PtySession is not None\n```\n\n\u003c/td>\u003c/tr>\u003c/table>\n\n\u003ctable>\n\u003ctr>\u003cth>\u003ccode>pkg/_pty/interface.py\u003c/code>\u003c/th>\u003c/tr>\n\u003ctr>\u003ctd>\n\n```python\nfrom __future__ import annotations\n\nfrom abc import ABC, abstractmethod\n\n\nclass PtySessionInterface(ABC):\n    def __init__(self, command: list[str]) -> None:\n        self.command = command\n\n    @abstractmethod\n    def get_exit_code(self) -> int | None: ...\n```\n\n\u003c/td>\u003c/tr>\u003c/table>\n\n\u003ctable>\n\u003ctr>\u003cth>\u003ccode>pkg/_pty/session.py\u003c/code>\u003c/th>\u003c/tr>\n\u003ctr>\u003ctd>\n\n```python\nfrom __future__ import annotations\n\nimport sys\n\nif sys.platform == \"win32\":\n    from .windows import PtySession\nelse:\n    from .unix import PtySession\n\n__all__ = [\"PtySession\"]\n```\n\n\u003c/td>\u003c/tr>\u003c/table>\n\n\u003ctable>\n\u003ctr>\u003cth>\u003ccode>pkg/_pty/unix.py\u003c/code>\u003c/th>\u003c/tr>\n\u003ctr>\u003ctd>\n\n```python\nfrom __future__ import annotations\n\nimport pty\n\nfrom .interface import PtySessionInterface\n\n\nclass PtySession(PtySessionInterface):\n    def __init__(self, command: list[str]) -> None:\n        super().__init__(command)\n\n        self._fd, self._child_fd = pty.openpty()\n\n    def get_exit_code(self) -> int | None:\n        return None\n```\n\n\u003c/td>\u003c/tr>\u003c/table>\n\n\u003ctable>\n\u003ctr>\u003cth>\u003ccode>pkg/_pty/windows.py\u003c/code>\u003c/th>\u003c/tr>\n\u003ctr>\u003ctd>\n\n```python\nfrom __future__ import annotations\n\nfrom .interface import PtySessionInterface\n\n\nclass PtySession(PtySessionInterface):\n    def __init__(self, command: list[str]) -> None:\n        super().__init__(command)\n\n        self._fd, self._child_fd = (0, 0)\n\n    def get_exit_code(self) -> int | None:\n        return None\n```\n\n\u003c/td>\u003c/tr>\u003c/table>\n\nFinally, enter the `mypy-issue` directory and run `mypy pkg` on Windows:\n\n```\n$ mypy pkg\npkg\\_pty\\unix.py:12: error: Module has no attribute \"openpty\"  [attr-defined]\n            self._fd, self._child_fd = pty.openpty()\n                                       ^~~~~~~~~~~\nFound 1 error in 1 file (checked 7 source files)\n```\n\n**Expected Behavior**\n\nI would expect that Mypy respects the platform condition like it does in other circumstances I've experienced and is documented.\n\n**Your Environment**\n\n- Mypy version used: mypy 1.15.0 (compiled: yes)\n- Python version used: 3.12","author":{"url":"https://github.com/ofek","@type":"Person","name":"ofek"},"datePublished":"2025-05-01T16:46:09Z","url":"https://github.com/python/mypy/issues/19009"}

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:d40dd63a-1277-22a7-3529-8d84f910c46e
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-id9454:144E47:2381BFF:2E1B411:6AFFEAD2
html-safe-nonceeed7c8d588021ecf669ab1adfb46b61da9c73906697f39e4861c87e5db91ccd1
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5NDU0OjE0NEU0NzoyMzgxQkZGOjJFMUI0MTE6NkFGRkVBRDIiLCJ2aXNpdG9yX2lkIjoiNjM4NjEyMDY2MTk3ODI2MjU4IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0=
visitor-hmac7f9a80b341049d0aacfaf657473faff528ac31b5c2e1b739c8a04089562217a4
hovercard-subject-tagissue:3034246843
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/mypy/19009/issue_layout
twitter:imagehttps://opengraph.githubassets.com/1e0c439e6e312168d5f6e6737ea59535fa16f9bab6c141eebae3a6ae93253aab/python/mypy/issues/19009
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/1e0c439e6e312168d5f6e6737ea59535fa16f9bab6c141eebae3a6ae93253aab/python/mypy/issues/19009
og:image:altBug Report When you have the following provider module: if sys.platform == "win32": from my_pkg._pty.windows import PtySession else: from my_pkg._pty.unix import PtySession and attempt importing th...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernameofek
hostnamegithub.com
expected-hostnamegithub.com
None0a0d8686a27478df474dd7415776a7a080cde8838b3cd92ea7601187572e5729
turbo-cache-controlno-preview
go-importgithub.com/python/mypy git https://github.com/python/mypy.git
octolytics-dimension-user_id1525981
octolytics-dimension-user_loginpython
octolytics-dimension-repository_id7053637
octolytics-dimension-repository_nwopython/mypy
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id7053637
octolytics-dimension-repository_network_root_nwopython/mypy
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
release16a11879678aaf97e2a42c33ee70830aa084fa37
ui-targetfull
theme-color#1e2327
color-schemelight dark
react-app-nameissues

Links:

Skip to contenthttps://github.com/python/mypy/issues/19009#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fmypy%2Fissues%2F19009
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%2Fmypy%2Fissues%2F19009
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%2Fmypy
Reloadhttps://github.com/python/mypy/issues/19009
Reloadhttps://github.com/python/mypy/issues/19009
Reloadhttps://github.com/python/mypy/issues/19009
pythonhttps://github.com/python
mypyhttps://github.com/python/mypy
Codehttps://github.com/python/mypy
Issues2.7k (2.7k)https://github.com/python/mypy/issues
Pull requests547 (547)https://github.com/python/mypy/pulls
Actionshttps://github.com/python/mypy/actions
Projectshttps://github.com/python/mypy/projects
Wikihttps://github.com/python/mypy/wiki
Security and qualityhttps://github.com/python/mypy/security
Insightshttps://github.com/python/mypy/insights
https://github.com/python/mypy
New issuehttps://github.com/login?return_to=https://github.com/python/mypy/issues/19009
New issuehttps://github.com/login?return_to=https://github.com/python/mypy/issues/19009
Conditional import of a class follows imports of all brancheshttps://github.com/python/mypy/issues/19009#top
bugmypy got something wronghttps://github.com/python/mypy/issues?q=state%3Aopen%20label%3A%22bug%22
pendingIssues that may be closedhttps://github.com/python/mypy/issues?q=state%3Aopen%20label%3A%22pending%22
topic-reachabilityDetecting unreachable codehttps://github.com/python/mypy/issues?q=state%3Aopen%20label%3A%22topic-reachability%22
https://github.com/ofek
ofekhttps://github.com/ofek
on May 1, 2025https://github.com/python/mypy/issues/19009#issue-3034246843
ofekhttps://github.com/ofek
bugmypy got something wronghttps://github.com/python/mypy/issues?q=state%3Aopen%20label%3A%22bug%22
on May 1, 2025https://github.com/python/mypy/issues/19009#event-17489779018
https://github.com/JelleZijlstra
JelleZijlstrahttps://github.com/JelleZijlstra
on May 1, 2025https://github.com/python/mypy/issues/19009#issuecomment-2845238420
https://github.com/ofek
ofekhttps://github.com/ofek
on May 1, 2025https://github.com/python/mypy/issues/19009#issuecomment-2845260891
https://github.com/sterliakov
sterliakovhttps://github.com/sterliakov
on May 1, 2025https://github.com/python/mypy/issues/19009#issuecomment-2845279637
#5308https://github.com/python/mypy/issues/5308
sterliakovhttps://github.com/sterliakov
topic-reachabilityDetecting unreachable codehttps://github.com/python/mypy/issues?q=state%3Aopen%20label%3A%22topic-reachability%22
pendingIssues that may be closedhttps://github.com/python/mypy/issues?q=state%3Aopen%20label%3A%22pending%22
on May 1, 2025https://github.com/python/mypy/issues/19009#event-17490122283
https://github.com/sterliakov
sterliakovhttps://github.com/sterliakov
on May 1, 2025https://github.com/python/mypy/issues/19009#issuecomment-2845289486
https://github.com/ofek
ofekhttps://github.com/ofek
on May 1, 2025https://github.com/python/mypy/issues/19009#issuecomment-2845294191
https://github.com/sterliakov
sterliakovhttps://github.com/sterliakov
on May 1, 2025https://github.com/python/mypy/issues/19009#issuecomment-2845322164
https://github.com/sterliakov
sterliakovhttps://github.com/sterliakov
on May 1, 2025https://github.com/python/mypy/issues/19009#issuecomment-2845328755
https://github.com/ofek
ofekhttps://github.com/ofek
on May 1, 2025https://github.com/python/mypy/issues/19009#issuecomment-2845336653
https://github.com/sterliakov
sterliakovhttps://github.com/sterliakov
on May 1, 2025https://github.com/python/mypy/issues/19009#issuecomment-2845357484
manual sectionhttps://mypy.readthedocs.io/en/latest/config_file.html#confval-platform
https://github.com/ofek
ofekhttps://github.com/ofek
on May 1, 2025https://github.com/python/mypy/issues/19009#issuecomment-2845793310
#19013https://github.com/python/mypy/issues/19013
ofekhttps://github.com/ofek
completedhttps://github.com/python/mypy/issues?q=is%3Aissue%20state%3Aclosed%20archived%3Afalse%20reason%3Acompleted
on May 1, 2025https://github.com/python/mypy/issues/19009#event-17492612482
Sign up for freehttps://github.com/signup?return_to=https://github.com/python/mypy/issues/19009
Sign in to commenthttps://github.com/login?return_to=https://github.com/python/mypy/issues/19009
bugmypy got something wronghttps://github.com/python/mypy/issues?q=state%3Aopen%20label%3A%22bug%22
pendingIssues that may be closedhttps://github.com/python/mypy/issues?q=state%3Aopen%20label%3A%22pending%22
topic-reachabilityDetecting unreachable codehttps://github.com/python/mypy/issues?q=state%3Aopen%20label%3A%22topic-reachability%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.