René's URL Explorer Experiment


Title: Rework starargs with union argument by randolf-scholz · Pull Request #19651 · python/mypy · GitHub

Open Graph Title: Rework starargs with union argument by randolf-scholz · Pull Request #19651 · python/mypy

X Title: Rework starargs with union argument by randolf-scholz · Pull Request #19651 · python/mypy

Description: Makes *args inference smarter by special casing UnionType *(tuple[A, B, C] | tuple[None|None|None]) gets treated like tuple[A | None, B | None, C | None] inside ArgTypeExpander (applies if all union member are fixed size tuples of equal length *(Iterable[X] | Iterable[Y]) gets treated like *Iterable[X | Y] inside ArgTypeExpander (applies if ① is not triggered) This gives some better inference in some cases: x: list[str | None] | list[str] reveal_type([*x]) # master: list[Any] PR: list[str | None] x2: tuple[int, int] | tuple[None, None] reveal_type( (*x2,) ) # master: tuple[Any, ...] PR: tuple[int | None, int | None] x3: tuple[int, int] | tuple[None, None, None] reveal_type( (*x3,) ) # master: tuple[Any, ...] PR: tuple[int | None, ...] See added unit tests for more examples. Fixes: #19662 Fixes: #19659 Fixes: #17161 Fixes: #15747 Fixes: #14470 Fixes: #15969 See Also: #19650, cc @hauntsaninja Dev notes: If we detect that the union has non-tuple elements or tuples of different sizes, we upcast-reinterpret every union member as some Iterable[T], then apply each union member, and then return the union of the results. Handling unions of finite size tuples with different sizes in infeasible, due to combinatoric explosion1 map_actuals_to_formals added special case for union of same sized tuples. ExpressionChecker.check_arg: added some extra logic that applies if the callee_type is UnpackType, but the actual_type got expanded from Unpack_type to something else. Previously, this only worked "by accident" because the expander was guaranteed to return AnyType(TypeOfAny.from_errors) in this case. ArgTypeExpander: Create a NewType alias IterableType for Iteralble[T], and helper functions is_iterable, is_iterable_instance_type, _make_iterable_instance_type. added _solve_as_iterable function that uses the solver to interpret a type as Iterable[T] added as_iterable_type that applies a few special cases (UnionType, etc. before calling the solver) added parse_star_args_type that converts the argument of *args to one of TupleType | IterableType | ParamSpecType | AnyType visit_tuple_expr: Applies ArgTypeExpander(*parse_star_args_type) to ensure consistent behavior across [*args], {*args} and (*args). Footnotes consider f(*x1, *x2, ..., *xn). If each $x_k$ is comprised of a union of $m_k$ differently sized tuples, then there are $m_1⋅m_2⋅…⋅m_k$ possible paths. ↩

Open Graph Description: Makes *args inference smarter by special casing UnionType *(tuple[A, B, C] | tuple[None|None|None]) gets treated like tuple[A | None, B | None, C | None] inside ArgTypeExpander (applies if all uni...

X Description: Makes *args inference smarter by special casing UnionType *(tuple[A, B, C] | tuple[None|None|None]) gets treated like tuple[A | None, B | None, C | None] inside ArgTypeExpander (applies if all uni...

Opengraph URL: https://github.com/python/mypy/pull/19651

X: @github

direct link

Domain: github.com

route-pattern/:user_id/:repository/pull/:id/commits/:range(.:format)
route-controllerpull_requests
route-actioncommits
fetch-noncev2:78e16a10-3a73-8349-fd62-9a8ab83c5a37
current-catalog-service-hashae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b
request-idAE42:1F8816:36219E0:480EC8A:6A65569E
html-safe-nonce44a20bd1c1976c441c164b5e8b026da1e19548b4bf64c438e5c41f370d1671e9
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBRTQyOjFGODgxNjozNjIxOUUwOjQ4MEVDOEE6NkE2NTU2OUUiLCJ2aXNpdG9yX2lkIjoiNTk0NzY4MDg0MDgxODcxMDE3NCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9
visitor-hmacb444e0ea16b50ce21126157ce68736535006e2b6ddce19ebcd7ca80de624c806
hovercard-subject-tagpull_request:2742706472
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/commits
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/python/mypy/pull/19651/commits/f2d254c0f6cde6c3bf51ed2f84004789d5471ecb
twitter:imagehttps://avatars.githubusercontent.com/u/39696536?s=400&v=4
twitter:cardsummary_large_image
og:imagehttps://avatars.githubusercontent.com/u/39696536?s=400&v=4
og:image:altMakes *args inference smarter by special casing UnionType *(tuple[A, B, C] | tuple[None|None|None]) gets treated like tuple[A | None, B | None, C | None] inside ArgTypeExpander (applies if all uni...
og:site_nameGitHub
og:typeobject
hostnamegithub.com
expected-hostnamegithub.com
None52c76df668885aaff23b50bdca1fa1ea44ac9c1553e888ebc70ff1e4daa4625b
turbo-cache-controlno-preview
diff-viewunified
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
release309153364422b3c499922d1a2a6404910a58ed8e
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/python/mypy/pull/19651/commits/f2d254c0f6cde6c3bf51ed2f84004789d5471ecb#start-of-content
https://github.com/
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fmypy%2Fpull%2F19651%2Fcommits%2Ff2d254c0f6cde6c3bf51ed2f84004789d5471ecb
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
Code QualityEnforce quality at mergehttps://github.com/features/code-quality
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%2Fpython%2Fmypy%2Fpull%2F19651%2Fcommits%2Ff2d254c0f6cde6c3bf51ed2f84004789d5471ecb
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%2Fcommits&source=header-repo&source_repo=python%2Fmypy
Reloadhttps://github.com/python/mypy/pull/19651/commits/f2d254c0f6cde6c3bf51ed2f84004789d5471ecb
Reloadhttps://github.com/python/mypy/pull/19651/commits/f2d254c0f6cde6c3bf51ed2f84004789d5471ecb
Reloadhttps://github.com/python/mypy/pull/19651/commits/f2d254c0f6cde6c3bf51ed2f84004789d5471ecb
Please reload this pagehttps://github.com/python/mypy/pull/19651/commits/f2d254c0f6cde6c3bf51ed2f84004789d5471ecb
python https://github.com/python
mypyhttps://github.com/python/mypy
Please reload this pagehttps://github.com/python/mypy/pull/19651/commits/f2d254c0f6cde6c3bf51ed2f84004789d5471ecb
Notifications https://github.com/login?return_to=%2Fpython%2Fmypy
Fork 3.3k https://github.com/login?return_to=%2Fpython%2Fmypy
Star 20.6k https://github.com/login?return_to=%2Fpython%2Fmypy
Code https://github.com/python/mypy
Issues 2.7k https://github.com/python/mypy/issues
Pull requests 474 https://github.com/python/mypy/pulls
Actions https://github.com/python/mypy/actions
Projects https://github.com/python/mypy/projects
Wiki https://github.com/python/mypy/wiki
Security and quality 0 https://github.com/python/mypy/security
Insights https://github.com/python/mypy/pulse
Code https://github.com/python/mypy
Issues https://github.com/python/mypy/issues
Pull requests https://github.com/python/mypy/pulls
Actions https://github.com/python/mypy/actions
Projects https://github.com/python/mypy/projects
Wiki https://github.com/python/mypy/wiki
Security and quality https://github.com/python/mypy/security
Insights https://github.com/python/mypy/pulse
Sign up for GitHub https://github.com/signup?return_to=%2Fpython%2Fmypy%2Fissues%2Fnew%2Fchoose
terms of servicehttps://docs.github.com/terms
privacy statementhttps://docs.github.com/privacy
Sign inhttps://github.com/login?return_to=%2Fpython%2Fmypy%2Fissues%2Fnew%2Fchoose
randolf-scholzhttps://github.com/randolf-scholz
python:masterhttps://github.com/python/mypy/tree/master
randolf-scholz:fix_list_comprehensionhttps://github.com/randolf-scholz/mypy/tree/fix_list_comprehension
Conversation 56 https://github.com/python/mypy/pull/19651
Commits 15 https://github.com/python/mypy/pull/19651/commits
Checks 19 https://github.com/python/mypy/pull/19651/checks
Files changed https://github.com/python/mypy/pull/19651/files
Please reload this pagehttps://github.com/python/mypy/pull/19651/commits/f2d254c0f6cde6c3bf51ed2f84004789d5471ecb
Rework starargs with union argument https://github.com/python/mypy/pull/19651/commits/f2d254c0f6cde6c3bf51ed2f84004789d5471ecb#top
Show all changes 15 commits https://github.com/python/mypy/pull/19651/files
245cba3 rework starargs with union argument randolf-scholz Aug 13, 2025 https://github.com/python/mypy/pull/19651/commits/245cba30d43f1659a150a1883d7e823bf8ad5dfa
f2d254c Use typing.Unpack in tests randolf-scholz Aug 14, 2025 https://github.com/python/mypy/pull/19651/commits/f2d254c0f6cde6c3bf51ed2f84004789d5471ecb
df7b3f0 reworked argmapper with star args randolf-scholz Aug 14, 2025 https://github.com/python/mypy/pull/19651/commits/df7b3f0409a5ec07cad3afbb02fcb64250e701e5
5e239a3 always use the solver meachnism randolf-scholz Aug 15, 2025 https://github.com/python/mypy/pull/19651/commits/5e239a3a5f27e3b2972b4398155574cd9c85af7f
6cbb237 fixed infer_constraints randolf-scholz Aug 15, 2025 https://github.com/python/mypy/pull/19651/commits/6cbb237ab06c6f5cf8538f567f9125b87c399234
115bf00 cleanup randolf-scholz Aug 15, 2025 https://github.com/python/mypy/pull/19651/commits/115bf00a02582f0e85d71d046774597ff3d702e3
08db3da Merge branch 'master' into fix_list_comprehension randolf-scholz Aug 15, 2025 https://github.com/python/mypy/pull/19651/commits/08db3da706be925ac560a94022d253e98a509571
fac1e07 address review randolf-scholz Aug 15, 2025 https://github.com/python/mypy/pull/19651/commits/fac1e07267c98421fbcc8978d2031c0ff59001ae
68bc671 Merge branch 'python:master' into fix_list_comprehension randolf-scholz Aug 15, 2025 https://github.com/python/mypy/pull/19651/commits/68bc67174f070c27e6ef98a8d42342c3fd2c8fef
e8dcf88 check paramspec flavor randolf-scholz Aug 15, 2025 https://github.com/python/mypy/pull/19651/commits/e8dcf880b18b98facdeb6dd330930743b82ec1e5
fe4289a Revert "check paramspec flavor" randolf-scholz Aug 15, 2025 https://github.com/python/mypy/pull/19651/commits/fe4289a8f5039b58339685622608b9b7ed9708f3
0139c12 update parse_star_args_type docstring randolf-scholz Aug 15, 2025 https://github.com/python/mypy/pull/19651/commits/0139c12a1b366edd708856897a4a036987e5573c
109b4f3 update parse_star_args_type docstring randolf-scholz Aug 15, 2025 https://github.com/python/mypy/pull/19651/commits/109b4f3b1d7aab22709337ec258805821dc86bb6
0a6d757 Merge branch 'master' into fix_list_comprehension randolf-scholz Aug 16, 2025 https://github.com/python/mypy/pull/19651/commits/0a6d7573357271a3ec920efcd959e4b2f0513016
e169d3e address review randolf-scholz Aug 16, 2025 https://github.com/python/mypy/pull/19651/commits/e169d3e33ac75a463c257aaf32d00ac0e0ee0cc8
Clear filters https://github.com/python/mypy/pull/19651/commits/f2d254c0f6cde6c3bf51ed2f84004789d5471ecb
Please reload this pagehttps://github.com/python/mypy/pull/19651/commits/f2d254c0f6cde6c3bf51ed2f84004789d5471ecb
Please reload this pagehttps://github.com/python/mypy/pull/19651/commits/f2d254c0f6cde6c3bf51ed2f84004789d5471ecb
Prev https://github.com/python/mypy/pull/19651/commits/245cba30d43f1659a150a1883d7e823bf8ad5dfa
Next https://github.com/python/mypy/pull/19651/commits/df7b3f0409a5ec07cad3afbb02fcb64250e701e5
Please reload this pagehttps://github.com/python/mypy/pull/19651/commits/f2d254c0f6cde6c3bf51ed2f84004789d5471ecb
https://github.com/randolf-scholz
randolf-scholzhttps://github.com/python/mypy/commits?author=randolf-scholz
test-data/unit/check-kwargs.testhttps://github.com/python/mypy/pull/19651/commits/f2d254c0f6cde6c3bf51ed2f84004789d5471ecb#diff-aeb853dc6775ad957836e3849f453e0405806c7234ff8587991f7be8917289dd
View file https://github.com/python/mypy/blob/f2d254c0f6cde6c3bf51ed2f84004789d5471ecb/test-data/unit/check-kwargs.test
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/python/mypy/pull/19651/commits/{{ revealButtonHref }}
https://github.com/python/mypy/pull/19651/commits/f2d254c0f6cde6c3bf51ed2f84004789d5471ecb#diff-aeb853dc6775ad957836e3849f453e0405806c7234ff8587991f7be8917289dd
https://github.com/python/mypy/pull/19651/commits/f2d254c0f6cde6c3bf51ed2f84004789d5471ecb#diff-aeb853dc6775ad957836e3849f453e0405806c7234ff8587991f7be8917289dd
https://github.com/python/mypy/pull/19651/commits/f2d254c0f6cde6c3bf51ed2f84004789d5471ecb#diff-aeb853dc6775ad957836e3849f453e0405806c7234ff8587991f7be8917289dd
https://github.com/python/mypy/pull/19651/commits/f2d254c0f6cde6c3bf51ed2f84004789d5471ecb#diff-aeb853dc6775ad957836e3849f453e0405806c7234ff8587991f7be8917289dd
https://github.com/python/mypy/pull/19651/commits/f2d254c0f6cde6c3bf51ed2f84004789d5471ecb#diff-aeb853dc6775ad957836e3849f453e0405806c7234ff8587991f7be8917289dd
https://github.com/python/mypy/pull/19651/commits/f2d254c0f6cde6c3bf51ed2f84004789d5471ecb#diff-aeb853dc6775ad957836e3849f453e0405806c7234ff8587991f7be8917289dd
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.