René's URL Explorer Experiment


Title: Consider loosening restrictions of `Final` · Issue #920 · python/typing · GitHub

Open Graph Title: Consider loosening restrictions of `Final` · Issue #920 · python/typing

X Title: Consider loosening restrictions of `Final` · Issue #920 · python/typing

Description: I think that Final is a very based idea, but I feel that it's current restrictions make using it painful. I think that split assignments should be allowed: def foo(cond: bool) -> None: if cond: a: Final = Funny("spam") else: a: Final = F...

Open Graph Description: I think that Final is a very based idea, but I feel that it's current restrictions make using it painful. I think that split assignments should be allowed: def foo(cond: bool) -> None: if cond: a: ...

X Description: I think that Final is a very based idea, but I feel that it's current restrictions make using it painful. I think that split assignments should be allowed: def foo(cond: bool) -> None: if co...

Opengraph URL: https://github.com/python/typing/issues/920

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Consider loosening restrictions of `Final`","articleBody":"I think that `Final` is a very based idea, but I feel that it's current restrictions make using it painful.\r\n\r\nI think that split assignments should be allowed:\r\n```py\r\ndef foo(cond: bool) -> None:\r\n    if cond:\r\n        a: Final = Funny(\"spam\")\r\n    else:\r\n        a: Final = Funny(\"eggs\")  # this is currently an error\r\n```\r\n\r\nMost languages allow this pattern to initialize constant variables:\r\n```py\r\ndef foo(cond: bool) -> None:\r\n    a: Final[Funny]\r\n    if cond:\r\n        a = Funny(\"spam\")\r\n    else:\r\n        a = Funny(\"eggs\")\r\n```\r\nI think these are convenient and enables `Final` to be used in more scenarios, but this is currently an error.\r\nBut this is allowed:\r\n```py\r\ndef foo(cond: bool) -> None:\r\n    a: Final = Funny(\"spam\") if cond else Funny(\"eggs\")\r\n```\r\n\u003cbr/>\r\n\r\nAnother issue I've found is the prohibition of `Final` declarations within loops:\r\n```py\r\ndef foo() -> None:\r\n    for i in [1,2,3]:\r\n        a: Final = i * 2  # currently an error\r\n        a = 10  # error\r\n        print(a)\r\n    print(a)\r\n    a = 10  # error\r\n```\r\nThis is defined in the pep: \r\n> Note that a type checker need not allow Final declarations inside loops since the runtime will see multiple assignments to the same variable in subsequent iterations.\r\n\r\nI understand that at runtime the same variable is reused for each iteration of the loop, but if you ignore that fact and just look at the semantic meaning of the code, it matches exactly to this Kotlin example:\r\n```kt\r\nfun foo() {\r\n    val a = listOf(1, 2, 3).map { i ->\r\n        val a = i\r\n        a = 10  // error\r\n        println(a)\r\n        a\r\n    }.last()\r\n    println(a)\r\n    a = 10  // error\r\n}\r\n```\r\nDisallowing `Final` in loops doesn't address any of the motivations listed in the pep, any I can't see any reason why it should be disallowed.\r\n\u003cbr/>\r\n\r\nAlso, why are `Final` annotations not allowed on functional arguments?\r\n> `Final` may only be used as the outermost type in assignments or variable annotations. Using it in any other position is an error. In particular, `Final` can't be used in annotations for function arguments:\r\n\r\nWhy? This is commonly seen in other languages. In Kotlin, function parameters can __only__ be `val`(Kotlin's form of `Final`), in Java a function parameter may be marked with `final`.","author":{"url":"https://github.com/DetachHead","@type":"Person","name":"DetachHead"},"datePublished":"2021-11-04T12:52:17Z","url":"https://github.com/python/typing/issues/920"}

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:2d2739e6-d2a4-39af-3238-b15f9ad64a2d
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-id98D4:2E9DBB:2368E6D:305A1A2:6B00321B
html-safe-nonce987414f8ee465bd0a576371accc2afd24cd5873c4a20fbaf22daf77dd6c9706f
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5OEQ0OjJFOURCQjoyMzY4RTZEOjMwNUExQTI6NkIwMDMyMUIiLCJ2aXNpdG9yX2lkIjoiNjU3MTY3ODY1NjIzNjYzMDU1NSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9
visitor-hmacd9c323a0802e930ae366e57ccc42eda5b6dc92642998b1b99e89c555088ef6ea
hovercard-subject-tagissue:1044730788
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/typing/920/issue_layout
twitter:imagehttps://opengraph.githubassets.com/371e7b8317f36eceaaaa058017918ccf6dfdd327a154c82b78ad270743518fd8/python/typing/issues/920
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/371e7b8317f36eceaaaa058017918ccf6dfdd327a154c82b78ad270743518fd8/python/typing/issues/920
og:image:altI think that Final is a very based idea, but I feel that it's current restrictions make using it painful. I think that split assignments should be allowed: def foo(cond: bool) -> None: if cond: a: ...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernameDetachHead
hostnamegithub.com
expected-hostnamegithub.com
None7d0829bbde9e48b2486cb5dd6d147896eb01d32134627091f818958a935ef3f0
turbo-cache-controlno-preview
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
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/python/typing/issues/920#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Ftyping%2Fissues%2F920
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%2Fissues%2F920
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%2Ftyping
Reloadhttps://github.com/python/typing/issues/920
Reloadhttps://github.com/python/typing/issues/920
Reloadhttps://github.com/python/typing/issues/920
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
https://github.com/python/typing
New issuehttps://github.com/login?return_to=https://github.com/python/typing/issues/920
New issuehttps://github.com/login?return_to=https://github.com/python/typing/issues/920
Consider loosening restrictions of Finalhttps://github.com/python/typing/issues/920#top
topic: featureDiscussions about new features for Python's type annotationshttps://github.com/python/typing/issues?q=state%3Aopen%20label%3A%22topic%3A%20feature%22
https://github.com/DetachHead
DetachHeadhttps://github.com/DetachHead
on Nov 4, 2021https://github.com/python/typing/issues/920#issue-1044730788
srittauhttps://github.com/srittau
topic: featureDiscussions about new features for Python's type annotationshttps://github.com/python/typing/issues?q=state%3Aopen%20label%3A%22topic%3A%20feature%22
on Nov 4, 2021https://github.com/python/typing/issues/920#event-5568111192
https://github.com/JukkaL
JukkaLhttps://github.com/JukkaL
on Nov 4, 2021https://github.com/python/typing/issues/920#issuecomment-961047729
https://github.com/hmc-cs-mdrissi
hmc-cs-mdrissihttps://github.com/hmc-cs-mdrissi
on Nov 4, 2021https://github.com/python/typing/issues/920#issuecomment-961247665
https://github.com/KotlinIsland
KotlinIslandhttps://github.com/KotlinIsland
on Nov 5, 2021https://github.com/python/typing/issues/920#issuecomment-961560629
@JukkaLhttps://github.com/JukkaL
@hmc-cs-mdrissihttps://github.com/hmc-cs-mdrissi
https://github.com/hmc-cs-mdrissi
hmc-cs-mdrissihttps://github.com/hmc-cs-mdrissi
on Feb 6, 2022https://github.com/python/typing/issues/920#issuecomment-1030832137
https://github.com/KotlinIsland
KotlinIslandhttps://github.com/KotlinIsland
on Feb 6, 2022https://github.com/python/typing/issues/920#issuecomment-1030855078
@hmc-cs-mdrissihttps://github.com/hmc-cs-mdrissi
https://github.com/erictraut
erictrauthttps://github.com/erictraut
on Feb 7, 2022https://github.com/python/typing/issues/920#issuecomment-1030962775
@KotlinIslandhttps://github.com/KotlinIsland
https://github.com/hmc-cs-mdrissi
hmc-cs-mdrissihttps://github.com/hmc-cs-mdrissi
on Feb 7, 2022https://github.com/python/typing/issues/920#issuecomment-1031070220
https://github.com/KotlinIsland
KotlinIslandhttps://github.com/KotlinIsland
on Feb 7, 2022https://github.com/python/typing/issues/920#issuecomment-1031072248
https://github.com/KotlinIsland
KotlinIslandhttps://github.com/KotlinIsland
on Feb 7, 2022https://github.com/python/typing/issues/920#issuecomment-1031094697
Sign up for freehttps://github.com/signup?return_to=https://github.com/python/typing/issues/920
Sign in to commenthttps://github.com/login?return_to=https://github.com/python/typing/issues/920
topic: featureDiscussions about new features for Python's type annotationshttps://github.com/python/typing/issues?q=state%3Aopen%20label%3A%22topic%3A%20feature%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.