René's URL Explorer Experiment


Title: [MNT]: Improve return type of `ioff` and `ion` to improve Pyright analysis of bound variables · Issue #27659 · matplotlib/matplotlib · GitHub

Open Graph Title: [MNT]: Improve return type of `ioff` and `ion` to improve Pyright analysis of bound variables · Issue #27659 · matplotlib/matplotlib

X Title: [MNT]: Improve return type of `ioff` and `ion` to improve Pyright analysis of bound variables · Issue #27659 · matplotlib/matplotlib

Description: Summary The following code causes Pyright (the type checker used by Pylance, default type checker for Python in VSCode) to emit an error: import matplotlib.pyplot as plt with plt.ioff(): fig, ax = plt.subplots() ax.plot([...], [...]) # <...

Open Graph Description: Summary The following code causes Pyright (the type checker used by Pylance, default type checker for Python in VSCode) to emit an error: import matplotlib.pyplot as plt with plt.ioff(): fig, ax = ...

X Description: Summary The following code causes Pyright (the type checker used by Pylance, default type checker for Python in VSCode) to emit an error: import matplotlib.pyplot as plt with plt.ioff(): fig, ax = ...

Opengraph URL: https://github.com/matplotlib/matplotlib/issues/27659

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"[MNT]: Improve return type of `ioff` and `ion` to improve Pyright analysis of bound variables","articleBody":"### Summary\r\n\r\nThe following code causes Pyright (the type checker used by Pylance, default type checker for Python in VSCode) to emit an error:\r\n\r\n```python\r\nimport matplotlib.pyplot as plt\r\n\r\nwith plt.ioff():\r\n    fig, ax = plt.subplots()\r\n\r\nax.plot([...], [...]) # \u003c-- Pyright error: \"ax\" is possibly unbound\r\n```\r\n\r\nThe root cause of the issue seems to be that `ioff` and `ion` return `contextlib.ExitStack`, which can in theory supress excpetions, as indicated by the return type of `ErrorStack.__exit__` being `bool` rather than `Literal[False]` or `None`. (See https://github.com/microsoft/pyright/issues/7009)\r\n\r\nIn practice though, the way matplotlib uses `ExitStack`, it can't swallow exceptions. It would be convenient for typed codebases if the return type of `ion` and `ioff` reflected that.\r\n\r\n### Proposed fix\r\n\r\nA simple context manager like this could be used instead to make it clear to type checkers that exceptions will never be supressed (note that the return type of `__exit__` is `None`):\r\n\r\n```python\r\nclass _InteractiveContextManager(contextlib.AbstractContextManager):\r\n    def __init__(self, callback: Callable):\r\n        self._callback = callback\r\n\r\n    def __enter__(self) -> None:\r\n        return None\r\n    \r\n    def __exit__(self, __exc_type, __exc_value, __traceback) -> None:\r\n        self._callback()\r\n```\r\nThis also has the added benefit that by returning `None` from `__enter__` we can better enforce that the context manager is not stored or accessed by the user. ","author":{"url":"https://github.com/FeldrinH","@type":"Person","name":"FeldrinH"},"datePublished":"2024-01-16T18:10:44Z","url":"https://github.com/matplotlib/matplotlib/issues/27659"}

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:914b19c2-d826-28cd-1fda-488d8ec43259
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-id8300:22E601:59CD02:78BA48:6B003282
html-safe-nonceda3e393bea4b6023d7ab45591d089d64c76a100792f83431a69d0661ac4b9654
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4MzAwOjIyRTYwMTo1OUNEMDI6NzhCQTQ4OjZCMDAzMjgyIiwidmlzaXRvcl9pZCI6IjE2MzAyNzg3OTE3NDgxMzc2MDIiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ==
visitor-hmac2ceaecb4c6533b23a6f563fa8a057827ff09f0ac876cd0f70cc743a0c55cb455
hovercard-subject-tagissue:2084547673
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/matplotlib/matplotlib/27659/issue_layout
twitter:imagehttps://opengraph.githubassets.com/e6a70a8151d7fb1889360720798277f470da61fe2b5ed85b77854d645dfc6fe3/matplotlib/matplotlib/issues/27659
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/e6a70a8151d7fb1889360720798277f470da61fe2b5ed85b77854d645dfc6fe3/matplotlib/matplotlib/issues/27659
og:image:altSummary The following code causes Pyright (the type checker used by Pylance, default type checker for Python in VSCode) to emit an error: import matplotlib.pyplot as plt with plt.ioff(): fig, ax = ...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernameFeldrinH
hostnamegithub.com
expected-hostnamegithub.com
None7d0829bbde9e48b2486cb5dd6d147896eb01d32134627091f818958a935ef3f0
turbo-cache-controlno-preview
go-importgithub.com/matplotlib/matplotlib git https://github.com/matplotlib/matplotlib.git
octolytics-dimension-user_id215947
octolytics-dimension-user_loginmatplotlib
octolytics-dimension-repository_id1385122
octolytics-dimension-repository_nwomatplotlib/matplotlib
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id1385122
octolytics-dimension-repository_network_root_nwomatplotlib/matplotlib
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
releasef3f3a43ca095cdea3abbb394112e971f9fdb94fa
ui-targetfull
theme-color#1e2327
color-schemelight dark
react-app-nameissues

Links:

Skip to contenthttps://github.com/matplotlib/matplotlib/issues/27659#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fmatplotlib%2Fmatplotlib%2Fissues%2F27659
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%2Fmatplotlib%2Fmatplotlib%2Fissues%2F27659
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=matplotlib%2Fmatplotlib
Reloadhttps://github.com/matplotlib/matplotlib/issues/27659
Reloadhttps://github.com/matplotlib/matplotlib/issues/27659
Reloadhttps://github.com/matplotlib/matplotlib/issues/27659
matplotlibhttps://github.com/matplotlib
matplotlibhttps://github.com/matplotlib/matplotlib
Codehttps://github.com/matplotlib/matplotlib
Issues1k (1k)https://github.com/matplotlib/matplotlib/issues
Pull requests430 (430)https://github.com/matplotlib/matplotlib/pulls
Actionshttps://github.com/matplotlib/matplotlib/actions
Projectshttps://github.com/matplotlib/matplotlib/projects
Wikihttps://github.com/matplotlib/matplotlib/wiki
Security and qualityhttps://github.com/matplotlib/matplotlib/security
Insightshttps://github.com/matplotlib/matplotlib/insights
https://github.com/matplotlib/matplotlib
New issuehttps://github.com/login?return_to=https://github.com/matplotlib/matplotlib/issues/27659
New issuehttps://github.com/login?return_to=https://github.com/matplotlib/matplotlib/issues/27659
#27667https://github.com/matplotlib/matplotlib/pull/27667
[MNT]: Improve return type of ioff and ion to improve Pyright analysis of bound variableshttps://github.com/matplotlib/matplotlib/issues/27659#top
#27667https://github.com/matplotlib/matplotlib/pull/27667
Maintenancehttps://github.com/matplotlib/matplotlib/issues?q=state%3Aopen%20label%3A%22Maintenance%22
topic: typinghttps://github.com/matplotlib/matplotlib/issues?q=state%3Aopen%20label%3A%22topic%3A%20typing%22
v3.9.0https://github.com/matplotlib/matplotlib/milestone/78
https://github.com/FeldrinH
FeldrinHhttps://github.com/FeldrinH
on Jan 16, 2024https://github.com/matplotlib/matplotlib/issues/27659#issue-2084547673
microsoft/pyright#7009https://github.com/microsoft/pyright/issues/7009
FeldrinHhttps://github.com/FeldrinH
Maintenancehttps://github.com/matplotlib/matplotlib/issues?q=state%3Aopen%20label%3A%22Maintenance%22
on Jan 16, 2024https://github.com/matplotlib/matplotlib/issues/27659#event-11502255650
dstansbyhttps://github.com/dstansby
topic: typinghttps://github.com/matplotlib/matplotlib/issues?q=state%3Aopen%20label%3A%22topic%3A%20typing%22
on Jan 16, 2024https://github.com/matplotlib/matplotlib/issues/27659#event-11502296678
https://github.com/tacaswell
tacaswellhttps://github.com/tacaswell
on Jan 16, 2024https://github.com/matplotlib/matplotlib/issues/27659#issuecomment-1894291218
https://github.com/FeldrinH
FeldrinHhttps://github.com/FeldrinH
on Jan 16, 2024https://github.com/matplotlib/matplotlib/issues/27659#issuecomment-1894297358
tacaswellhttps://github.com/tacaswell
v3.9.0https://github.com/matplotlib/matplotlib/milestone/78
on Jan 16, 2024https://github.com/matplotlib/matplotlib/issues/27659#event-11502534976
https://github.com/anntzer
anntzerhttps://github.com/anntzer
on Jan 18, 2024https://github.com/matplotlib/matplotlib/issues/27659#issuecomment-1898553509
https://discuss.python.org/t/add-an-else-clause-to-with-statements-to-detect-early-termination/38031/1https://discuss.python.org/t/add-an-else-clause-to-with-statements-to-detect-early-termination/38031/1
https://discuss.python.org/t/add-an-else-clause-to-with-statements-to-detect-early-termination/38031/54https://discuss.python.org/t/add-an-else-clause-to-with-statements-to-detect-early-termination/38031/54
https://github.com/FeldrinH
FeldrinHhttps://github.com/FeldrinH
on Jan 18, 2024https://github.com/matplotlib/matplotlib/issues/27659#issuecomment-1898770212
https://discuss.python.org/t/add-an-else-clause-to-with-statements-to-detect-early-termination/38031/1https://discuss.python.org/t/add-an-else-clause-to-with-statements-to-detect-early-termination/38031/1
https://discuss.python.org/t/add-an-else-clause-to-with-statements-to-detect-early-termination/38031/54https://discuss.python.org/t/add-an-else-clause-to-with-statements-to-detect-early-termination/38031/54
herehttps://github.com/python/typeshed/pull/11048#issuecomment-1819915637
https://github.com/tacaswell
tacaswellhttps://github.com/tacaswell
on Jan 18, 2024https://github.com/matplotlib/matplotlib/issues/27659#issuecomment-1899011964
https://github.com/FeldrinH
FeldrinHhttps://github.com/FeldrinH
on Jan 18, 2024https://github.com/matplotlib/matplotlib/issues/27659#issuecomment-1899144175
https://github.com/anntzer
anntzerhttps://github.com/anntzer
on Jan 18, 2024https://github.com/matplotlib/matplotlib/issues/27659#issuecomment-1899155029
https://github.com/FeldrinH
FeldrinHhttps://github.com/FeldrinH
on Jan 18, 2024https://github.com/matplotlib/matplotlib/issues/27659#issuecomment-1899163441
QuLogichttps://github.com/QuLogic
completedhttps://github.com/matplotlib/matplotlib/issues?q=is%3Aissue%20state%3Aclosed%20archived%3Afalse%20reason%3Acompleted
#27667https://github.com/matplotlib/matplotlib/pull/27667
on Feb 23, 2024https://github.com/matplotlib/matplotlib/issues/27659#event-11898167324
Sign up for freehttps://github.com/signup?return_to=https://github.com/matplotlib/matplotlib/issues/27659
Sign in to commenthttps://github.com/login?return_to=https://github.com/matplotlib/matplotlib/issues/27659
Maintenancehttps://github.com/matplotlib/matplotlib/issues?q=state%3Aopen%20label%3A%22Maintenance%22
topic: typinghttps://github.com/matplotlib/matplotlib/issues?q=state%3Aopen%20label%3A%22topic%3A%20typing%22
v3.9.0https://github.com/matplotlib/matplotlib/milestone/78
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.