René's URL Explorer Experiment


Title: Refactor Union, Tuple, and Callable by ilevkivskyi · Pull Request #308 · python/typing · GitHub

Open Graph Title: Refactor Union, Tuple, and Callable by ilevkivskyi · Pull Request #308 · python/typing

X Title: Refactor Union, Tuple, and Callable by ilevkivskyi · Pull Request #308 · python/typing

Description: Fixes #301 now List[Tuple[T, T]][int] == List[Tuple[int, int]] Fixes #298 now Table = Tuple[T, List[T]] can be used as generic type alias (as in PEP 484 example) Fixes #299 now class MyTup(Tuple[int, ...]): ... is allowed Fixes #156 (well, it does not substitute the annotations, but makes this task simple even in complex cases, see example in tests) Also this PR fixes some minor things that I have found while working on this: List[Union] (with bare Union, i.e. without arguments), List[Optional], List[Generic[T]], and List[ClassVar[int]] are not valid and are prohibited now. Generic did not evaluate forward references when asked, now it does. __qualname__ was not copied on generic class subscription. Type was not erased on instantiation of subclasses of concrete containers (List, Set, etc). There was an obscure bug in Python 2: sometimes _abc_registry was erased on instantiation. The main idea of this PR is to fix the issues mentioned at the top by reusing the existing code. Namely, I pulled flattening and removing duplicates code from _Union and the tree calculation function _subs_tree from GenericMeta. As well I moved Tuple and Callable after GenericMeta and made them inherit the latter. So that now all types that could be generic store their info in common way using __origin__, __parameters__, __args__. I tried to polish this, to be sure that nothing was broken in the process of "refactoring" (also to improve speed). There is no recursion, the substitution tree is recalculated only when necessary. Also I added a lot of tests and many comments/docstrings (also for things added in my recent PRs). @gvanrossum Could you please take a look at this? I would like this to get into 3.6b3, so that it will have a chance to be thoroughly tested.

Open Graph Description: Fixes #301 now List[Tuple[T, T]][int] == List[Tuple[int, int]] Fixes #298 now Table = Tuple[T, List[T]] can be used as generic type alias (as in PEP 484 example) Fixes #299 now class MyTup(Tuple[in...

X Description: Fixes #301 now List[Tuple[T, T]][int] == List[Tuple[int, int]] Fixes #298 now Table = Tuple[T, List[T]] can be used as generic type alias (as in PEP 484 example) Fixes #299 now class MyTup(Tuple[in...

Opengraph URL: https://github.com/python/typing/pull/308

X: @github

direct link

Domain: github.com

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/:user_id/:repository/pull/:id/files(.:format)
route-controllerpull_requests
route-actionfiles
fetch-noncev2:bd9ef62c-9849-f3c5-f20b-5edf033bd250
current-catalog-service-hashae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b
request-idA888:2A087:1ECCDD:297EED:6B00223C
html-safe-nonce15dcea8c18a96b6aec083e810734f8fefb7f36f63d2e6355a9e7eccfa473b258
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBODg4OjJBMDg3OjFFQ0NERDoyOTdFRUQ6NkIwMDIyM0MiLCJ2aXNpdG9yX2lkIjoiNDU3NzY4NTA3OTEyNzQ5OTMyNCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9
visitor-hmac8b607998ba72ae633684031bd1eb7d6303c42b33c7975b75f19749ff7b3e4f3f
hovercard-subject-tagpull_request:90824456
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/python/typing/pull/308/files
twitter:imagehttps://avatars.githubusercontent.com/u/12005495?s=400&v=4
twitter:cardsummary_large_image
og:imagehttps://avatars.githubusercontent.com/u/12005495?s=400&v=4
og:image:altFixes #301 now List[Tuple[T, T]][int] == List[Tuple[int, int]] Fixes #298 now Table = Tuple[T, List[T]] can be used as generic type alias (as in PEP 484 example) Fixes #299 now class MyTup(Tuple[in...
og:site_nameGitHub
og:typeobject
hostnamegithub.com
expected-hostnamegithub.com
None4eb4cba0d69f045374ac15de9666d22b0961e1d555cc3824f36b7734c00c78e0
turbo-cache-controlno-preview
diff-viewunified
go-importgithub.com/python/typing git https://github.com/python/typing.git
octolytics-dimension-user_id1525981
octolytics-dimension-user_loginpython
octolytics-dimension-repository_id24604008
octolytics-dimension-repository_nwopython/typing
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id24604008
octolytics-dimension-repository_network_root_nwopython/typing
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
release44c658b24abf00491fb7ae5f56d42c9f38cbeab2
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/python/typing/pull/308/files#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Ftyping%2Fpull%2F308%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%2Fpython%2Ftyping%2Fpull%2F308%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=python%2Ftyping
Reloadhttps://github.com/python/typing/pull/308/files
Reloadhttps://github.com/python/typing/pull/308/files
Reloadhttps://github.com/python/typing/pull/308/files
pythonhttps://github.com/python
typinghttps://github.com/python/typing
Codehttps://github.com/python/typing
Issues206 (206)https://github.com/python/typing/issues
Pull requests27 (27)https://github.com/python/typing/pulls
Discussionshttps://github.com/python/typing/discussions
Actionshttps://github.com/python/typing/actions
Security and qualityhttps://github.com/python/typing/security
Insightshttps://github.com/python/typing/insights
Sign up for GitHub https://github.com/signup?return_to=%2Fpython%2Ftyping%2Fissues%2Fnew%2Fchoose
terms of servicehttps://docs.github.com/terms
privacy statementhttps://docs.github.com/privacy
Sign inhttps://github.com/login?return_to=%2Fpython%2Ftyping%2Fissues%2Fnew%2Fchoose
gvanrossumhttps://github.com/gvanrossum
python:masterhttps://github.com/python/typing/tree/master
ilevkivskyi:the-big-synchttps://github.com/ilevkivskyi/typehinting/tree/the-big-sync
Conversation 8 https://github.com/python/typing/pull/308
Commits 39 https://github.com/python/typing/pull/308/commits
Checks 0 https://github.com/python/typing/pull/308/checks
Files changed https://github.com/python/typing/pull/308/files
Please reload this pagehttps://github.com/python/typing/pull/308/files
Refactor Union, Tuple, and Callable https://github.com/python/typing/pull/308/files#top
Show all changes 39 commits https://github.com/python/typing/pull/308/files
e8c3ad6 Make Tuple[T, S] subcriptable and subclassable ilevkivskyi Oct 23, 2016 https://github.com/python/typing/pull/308/commits/e8c3ad6eebd4942e99d2fe0aef7f99e1e2c854e7
cfcf81f Make Callable[..., T] subscriptable and subclassable ilevkivskyi Oct 23, 2016 https://github.com/python/typing/pull/308/commits/cfcf81f39d0083151eeb90cbd20a854cbf13292f
1368e97 Make Union[T, S] subsctiptable ilevkivskyi Oct 23, 2016 https://github.com/python/typing/pull/308/commits/1368e976a20b071bd9dfa9a741c8534330021279
7ee4a1a Disable plain Union and Optional as type arguments ilevkivskyi Oct 23, 2016 https://github.com/python/typing/pull/308/commits/7ee4a1a1cc9d6c26f1432bd2d6552024efc7f75e
5fdceba Implement __eq__ for GenericMeta ilevkivskyi Oct 23, 2016 https://github.com/python/typing/pull/308/commits/5fdceba8144133eef7790e72d6edfd8d9f27b733
f339586 Implement __eq__ for Unions ilevkivskyi Oct 23, 2016 https://github.com/python/typing/pull/308/commits/f3395860a39e858a92615cba26387afb1a88e17f
26f50a3 Refactor common code in __eq__ and __repr__ ilevkivskyi Oct 23, 2016 https://github.com/python/typing/pull/308/commits/26f50a3b68cf55de825466faa67d01346393861d
65de907 Remove redundant code ilevkivskyi Oct 23, 2016 https://github.com/python/typing/pull/308/commits/65de9072034976cf639c2215a4f9671a814f2c1c
897de4e Fix minor bugs + mini-refactoring ilevkivskyi Oct 23, 2016 https://github.com/python/typing/pull/308/commits/897de4e7e0d468478aa272d0147143c5b5f0b0ac
c687ffa Fix repr of Callable subclasses ilevkivskyi Oct 23, 2016 https://github.com/python/typing/pull/308/commits/c687ffab2dc6bacf0ea949d30074d7fb2b685382
582a37f Don't be too pedantic in GenericMeta._eval_type ilevkivskyi Oct 23, 2016 https://github.com/python/typing/pull/308/commits/582a37f541a7251f390ed71ec3f00953c6035328
02e6b14 Simplify __hash__ and factor out orig_chain ilevkivskyi Oct 23, 2016 https://github.com/python/typing/pull/308/commits/02e6b14f522f933e18b5948976d07e627d73fb05
8d802cc Remove outdated tests + be more pedanctic in _Union._eval_type ilevkivskyi Oct 23, 2016 https://github.com/python/typing/pull/308/commits/8d802cc325f05e1707fc0d6cc3556bdaaf26d860
4e2527c Add tests ilevkivskyi Oct 23, 2016 https://github.com/python/typing/pull/308/commits/4e2527c000759468d960d8cbb741d9e41b8cc0eb
92da67f Factor out _subs_tree for Union and Generic ilevkivskyi Oct 24, 2016 https://github.com/python/typing/pull/308/commits/92da67fd6a9313e5cfbe70e9b0980d1bee527751
7563c92 Prohibit plain Generic[T] as type argument ilevkivskyi Oct 24, 2016 https://github.com/python/typing/pull/308/commits/7563c92e19c01cde51889a20e65176936d85234e
f33545b Correct a comment ilevkivskyi Oct 24, 2016 https://github.com/python/typing/pull/308/commits/f33545b2161471302a413cdd634502ed1075e5fe
4a996b2 Erase but preserve type also for Callable ilevkivskyi Oct 24, 2016 https://github.com/python/typing/pull/308/commits/4a996b2e53d6907edfde44bd40165450914e3017
6564742 Erase but preserve type for all generics ilevkivskyi Oct 24, 2016 https://github.com/python/typing/pull/308/commits/6564742cba2e9eeeee946553df8bee893b09b9b2
184f089 Restore original __next_in_mro__ and use more precise bases Oct 24, 2016 https://github.com/python/typing/pull/308/commits/184f0899d1e758d400e49cbfc1bb0510eb22361f
b613325 Preserve __qualname__ on subscription Oct 24, 2016 https://github.com/python/typing/pull/308/commits/b613325c09e1c24d7f5e06a78638d1d4489b31bd
011b9d8 Add tests and factor common stuff for Union ilevkivskyi Oct 24, 2016 https://github.com/python/typing/pull/308/commits/011b9d86c7eb65a41a9f2c7a67df3fad25722fef
52712a6 Add even more tests ilevkivskyi Oct 24, 2016 https://github.com/python/typing/pull/308/commits/52712a6c82f8b63a2f0ca1147c4ff397ccd61579
2641151 One more test + minor code simplification ilevkivskyi Oct 24, 2016 https://github.com/python/typing/pull/308/commits/26411514cb0818e9220166557fb12076bd92bbb5
9f1fb98 Polishing code ilevkivskyi Oct 25, 2016 https://github.com/python/typing/pull/308/commits/9f1fb98df873cf8828dfdb6d8e3099e3f1176fbd
279a67e Minor changes ilevkivskyi Oct 25, 2016 https://github.com/python/typing/pull/308/commits/279a67ed26165e62df53b1d7d0254b865f9a9094
f173fde Precalculate hash + refactor + more tests ilevkivskyi Oct 25, 2016 https://github.com/python/typing/pull/308/commits/f173fde3fc5525bfc5ee172e2b7f078a0f61a1b5
819d472 Simplify repr for Union ilevkivskyi Oct 25, 2016 https://github.com/python/typing/pull/308/commits/819d4721b451c9a9500183d3092bf160d64343e8
e6f19a8 Add big test for __eq__, __repr__, and Any substitution ilevkivskyi Oct 25, 2016 https://github.com/python/typing/pull/308/commits/e6f19a8ea1f1770ed30c0e0ab3afd495d0d5ad6b
deed806 Add test to illustrate substitution ilevkivskyi Oct 25, 2016 https://github.com/python/typing/pull/308/commits/deed806d5c21a938260895eec34e1235d1078cd0
f6382a7 Minor change in tests ilevkivskyi Oct 25, 2016 https://github.com/python/typing/pull/308/commits/f6382a79cc29c3350bed53115dab1702fbe8cd9c
9bc7374 Add/expand comments and docstrings ilevkivskyi Oct 25, 2016 https://github.com/python/typing/pull/308/commits/9bc7374b01ad325bf9ca67be683e5a7ae4a008f0
c2724ce Fix the __qualname__ in PY 3.2 ilevkivskyi Oct 25, 2016 https://github.com/python/typing/pull/308/commits/c2724cebda2e2e0d7b1d8d181c1f4da81374b742
fd3e344 Add tests to Python 2 ilevkivskyi Oct 25, 2016 https://github.com/python/typing/pull/308/commits/fd3e3442888cbe23a2d75dc22e8633d14552ca7f
cd7bbe2 Modify Union in Python 2 ilevkivskyi Oct 25, 2016 https://github.com/python/typing/pull/308/commits/cd7bbe2329ac7c99e135dd7870c030112ef354d1
068ab5e Update Python 2 tests ilevkivskyi Oct 25, 2016 https://github.com/python/typing/pull/308/commits/068ab5eb2f1db61c796edd0c944a9e6a4bf3552f
09c4797 Change remaining parts in Python 2 ilevkivskyi Oct 25, 2016 https://github.com/python/typing/pull/308/commits/09c47977348e718a7e03f4f1e963afb8ebb5be82
60303f7 Fix final test in PY 2 ilevkivskyi Oct 25, 2016 https://github.com/python/typing/pull/308/commits/60303f7204eaa66d5f1ba36211ae9138409225f4
ea5dd05 Also call super().__init__ in PY 2 Generic ilevkivskyi Oct 26, 2016 https://github.com/python/typing/pull/308/commits/ea5dd0546f749bbceab7d0b572f84354c1a72acb
Clear filters https://github.com/python/typing/pull/308/files
Please reload this pagehttps://github.com/python/typing/pull/308/files
Please reload this pagehttps://github.com/python/typing/pull/308/files
test_typing.py https://github.com/python/typing/pull/308/files#diff-f23c53e6fa002cdeac74b9499d744b9492bfd34a58ce281c2b5076e628d0083a
typing.py https://github.com/python/typing/pull/308/files#diff-cbea31cd6366bdaf7805202979325ba4b14a29613bb7aeaecf9a18e94ea93619
test_typing.py https://github.com/python/typing/pull/308/files#diff-e618ee6a4894a62d9269e41c4dc836e31e8224cfb66b5be3b325f4798ec245e3
typing.py https://github.com/python/typing/pull/308/files#diff-ad6da8dfad5c336100410e57073641a0266b69e1801476d2b1e593b2c04f81f5
python2/test_typing.pyhttps://github.com/python/typing/pull/308/files#diff-f23c53e6fa002cdeac74b9499d744b9492bfd34a58ce281c2b5076e628d0083a
View file https://github.com/ilevkivskyi/typehinting/blob/ea5dd0546f749bbceab7d0b572f84354c1a72acb/python2/test_typing.py
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/python/typing/pull/308/{{ revealButtonHref }}
https://github.com/python/typing/pull/308/files#diff-f23c53e6fa002cdeac74b9499d744b9492bfd34a58ce281c2b5076e628d0083a
https://github.com/python/typing/pull/308/files#diff-f23c53e6fa002cdeac74b9499d744b9492bfd34a58ce281c2b5076e628d0083a
https://github.com/python/typing/pull/308/files#diff-f23c53e6fa002cdeac74b9499d744b9492bfd34a58ce281c2b5076e628d0083a
https://github.com/python/typing/pull/308/files#diff-f23c53e6fa002cdeac74b9499d744b9492bfd34a58ce281c2b5076e628d0083a
https://github.com/python/typing/pull/308/files#diff-f23c53e6fa002cdeac74b9499d744b9492bfd34a58ce281c2b5076e628d0083a
https://github.com/python/typing/pull/308/files#diff-f23c53e6fa002cdeac74b9499d744b9492bfd34a58ce281c2b5076e628d0083a
https://github.com/python/typing/pull/308/files#diff-f23c53e6fa002cdeac74b9499d744b9492bfd34a58ce281c2b5076e628d0083a
https://github.com/python/typing/pull/308/files#diff-f23c53e6fa002cdeac74b9499d744b9492bfd34a58ce281c2b5076e628d0083a
https://github.com/python/typing/pull/308/files#diff-f23c53e6fa002cdeac74b9499d744b9492bfd34a58ce281c2b5076e628d0083a
https://github.com/python/typing/pull/308/files#diff-f23c53e6fa002cdeac74b9499d744b9492bfd34a58ce281c2b5076e628d0083a
Please reload this pagehttps://github.com/python/typing/pull/308/files
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.