René's URL Explorer Experiment


Title: Flag for disallowing Any · Issue #3470 · python/mypy · GitHub

Open Graph Title: Flag for disallowing Any · Issue #3470 · python/mypy

X Title: Flag for disallowing Any · Issue #3470 · python/mypy

Description: In general, we want to provide the user with a flag to disallow the use of implicit and explicit Any types as well as expressions with type Any, so that they can make sure all of their code is typechecked. @ddfisher and I did some brains...

Open Graph Description: In general, we want to provide the user with a flag to disallow the use of implicit and explicit Any types as well as expressions with type Any, so that they can make sure all of their code is type...

X Description: In general, we want to provide the user with a flag to disallow the use of implicit and explicit Any types as well as expressions with type Any, so that they can make sure all of their code is type...

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

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Flag for disallowing Any","articleBody":"In general, we want to provide the user with a flag to disallow the use of implicit and explicit Any types as well as expressions with type Any, so that they can make sure all of their code is typechecked.\r\n\r\n@ddfisher and I did some brainstorming yesterday and this proposal is what we came to.\r\nHere are all the places that `Any` can appear in, followed by discussion of the current state of the flags and the proposal for a new flag.\r\n\r\n# Types\r\n## Explicit\r\n\r\nA user can explicitly specify an `Any` type in variable definition (`x: Any = \"hello\"`), function definition(`def foo() → Any: ...`), a cast(`cast(Any, x)`), class definition (`class C(Any)`),  `NewType`, a `TypeVar`, `NamedTuple`, or part of a type(`List[Any]`). \r\n\r\n## Implicit\r\n\r\n### Unimported\r\nUnimported types happen when we try to use a type from an import from a module we don’t analyze. This could happen if we’re using `--follow-imports=skip` or `--ignore-missing-imports`. \r\nConsider the following example\r\n```\r\n    # unanalyzed.py\r\n    class C:\r\n        pass\r\n```\r\n```\r\n    # test.py\r\n    from unanalyzed import C\r\n    \r\n    def foo(c: C) -> str:\r\n        return c\r\n```\r\nIf you run `mypy test.py --follow-imports=skip`, the code typechecks from mypy’s point of view. Because `C` is unresolved, it implicitly becomes an alias for `Any`. \r\n\r\n### Omitted Generics\r\nThis case occurs when the user does not explicitly specify a generic parameter for a type. For instance, `List` in a type position becomes `List[Any]`. It is easy to forget to specify a generic parameter.  This can also happen with e.g. lower-case `list` from builtins.\r\n\r\nWe should consider disallowing omitting the generic parameter and maybe forbid using builtin types in favor of types from `typing` module. The proposal for it is [here](https://github.com/python/mypy/issues/3469).\r\n\r\n\r\n### Omitted Function Signature element\r\nWhen a user does not specify an explicit type for a parameter or a return type, it becomes `Any`. \r\nFor example, the function `def foo(x) → None: …`\r\nimplicitly becomes: `def foo(x: Any) → None: …`\r\n\r\n### From Error\r\n`Any` types can come from an ignored error. For instance:\r\n\r\n    from typing import Union\r\n    T = Union[UhOh]  # type: ignore\r\n    x: T\r\n    reveal_type(x) # error: Revealed type is 'Any'\r\n\r\n### Expressions\r\n\r\nAn expression of type `Any` can come from any `Any` types described above. \r\nFor instance, `x + y` gets type `Any` when `x` has type `Any` even if `y` doesn't.\r\n\r\nIn real-life code, it would be challenging to achieve no `Any` expressions in the entire module. Note that if the user is calling an untyped method from a different module, expression can have an `Any` type, even if all `Any` types are disallowed in the current module. Still, users may want the ability to disallow expressions of type `Any` completely in certain circumstances.\r\n\r\n\r\n----------\r\n# Current State\r\n## Unimported types\r\n\r\nCurrently, there is a PR (https://github.com/python/mypy/pull/3405) that adds a flag to disallow unimported types. \r\n\r\n\r\n## Omitted Generics\r\n\r\nThere is currently a [PR](https://github.com/python/mypy/pull/3141) for a flag that would give a warning on omitted generic types. I believe we should at the very least have it on by default. Ideally, we should forbid omitted generics.\r\n\r\n\r\n## Omitted Function\r\n\r\nFlag `--disallow-untyped-defs` is already implemented in https://github.com/python/mypy/pull/1285. This functionality should be merged into the new flag.\r\n\r\n\r\n## From Error\r\n\r\nCurrently, there is no flag to disable it.\r\n\r\n## Expressions\r\n\r\nCurrently, there is no flag to disable it.\r\n\r\n----------\r\n# Flag\r\n\r\nAll of these are very similar in their nature and it would make sense to have one flag to rule them all. \r\nIt is generally worth it to provide a user with an option to disable each of the types of Anys.\r\nThere are several ways to do it.\r\n\r\n\r\n## Have a different flag for each type\r\n\r\nCurrently, in order to disable a type of Any, you have to use a separate flag for each type. At the very least we should name the flags with similar names because the options are very closely related to each other. \r\n\r\n## Have several “umbrella” flags\r\n\r\nAn option would be to have several flags that would cover different types. For instance, `--disallow-unimported-any-types`, `--disallow-ommited-function-types`, `--disallow-implicit-any-types`, `--disallow-explicit-any-types`, and `--disallow-all-any`.\r\nHowever, having this many flags is cumbersome, especially when they overlap. The documentation and usage would be confusing.\r\n\r\n\r\n## Have One Flag with List of Options\r\n\r\nI think the best option is to have one flag that takes a list of arguments.\r\nThis could look something like this:\r\n`--disallow-any=...` where `...` can be `all`, `unimported`, `omitted`,`error`, `expr`\r\nWe should also be able to combine several into one, like this: `--disallow-any=unimported,omitted`. This combination, for example, would disallow imported types and disallow omitted function types. \r\nIf the flag parameters are `all` + any other flag, we should give an error saying that it’s redundant and linking to documentation.\r\n","author":{"url":"https://github.com/ilinum","@type":"Person","name":"ilinum"},"datePublished":"2017-05-27T00:13:22Z","url":"https://github.com/python/mypy/issues/3470"}

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:7f505ad3-80cf-8061-2375-06d97260b3e8
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idBFDE:3E1398:4E7AF1:6927C9:6B002F5C
html-safe-nonce0736a869495fd76f2976db7bf109e3ec64ee8729ec38cddf918a59310ac7ff3f
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCRkRFOjNFMTM5ODo0RTdBRjE6NjkyN0M5OjZCMDAyRjVDIiwidmlzaXRvcl9pZCI6Ijg1NDgxODc0Mzg2NjM2MTAyMDQiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ==
visitor-hmac93e29bdbe8b0e1309082fe366e75aa444819a1ff33a268511b540396fb664757
hovercard-subject-tagissue:231760293
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/3470/issue_layout
twitter:imagehttps://opengraph.githubassets.com/32e9c2b50304f9353c0ea2b97e4b407a5b50b34b9c103383ab4db470f5167140/python/mypy/issues/3470
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/32e9c2b50304f9353c0ea2b97e4b407a5b50b34b9c103383ab4db470f5167140/python/mypy/issues/3470
og:image:altIn general, we want to provide the user with a flag to disallow the use of implicit and explicit Any types as well as expressions with type Any, so that they can make sure all of their code is type...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernameilinum
hostnamegithub.com
expected-hostnamegithub.com
None7d0829bbde9e48b2486cb5dd6d147896eb01d32134627091f818958a935ef3f0
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
releasef3f3a43ca095cdea3abbb394112e971f9fdb94fa
ui-targetfull
theme-color#1e2327
color-schemelight dark
react-app-nameissues

Links:

Skip to contenthttps://github.com/python/mypy/issues/3470#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fmypy%2Fissues%2F3470
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%2F3470
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/3470
Reloadhttps://github.com/python/mypy/issues/3470
Reloadhttps://github.com/python/mypy/issues/3470
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/3470
New issuehttps://github.com/login?return_to=https://github.com/python/mypy/issues/3470
Flag for disallowing Anyhttps://github.com/python/mypy/issues/3470#top
https://github.com/ilinum
https://github.com/ilinum
ilinumhttps://github.com/ilinum
on May 27, 2017https://github.com/python/mypy/issues/3470#issue-231760293
@ddfisherhttps://github.com/ddfisher
herehttps://github.com/python/mypy/issues/3469
#3405https://github.com/python/mypy/pull/3405
PRhttps://github.com/python/mypy/pull/3141
#1285https://github.com/python/mypy/pull/1285
https://github.com/gvanrossum
gvanrossumhttps://github.com/gvanrossum
on May 29, 2017https://github.com/python/mypy/issues/3470#issuecomment-304570889
https://github.com/JelleZijlstra
JelleZijlstrahttps://github.com/JelleZijlstra
on May 29, 2017https://github.com/python/mypy/issues/3470#issuecomment-304574160
https://github.com/gvanrossum
gvanrossumhttps://github.com/gvanrossum
on May 30, 2017https://github.com/python/mypy/issues/3470#issuecomment-304757950
https://github.com/ilinum
ilinumhttps://github.com/ilinum
on May 30, 2017https://github.com/python/mypy/issues/3470#issuecomment-305015411
https://github.com/gvanrossum
gvanrossumhttps://github.com/gvanrossum
on May 30, 2017https://github.com/python/mypy/issues/3470#issuecomment-305017740
https://github.com/ilinum
ilinumhttps://github.com/ilinum
on May 30, 2017https://github.com/python/mypy/issues/3470#issuecomment-305023088
https://github.com/gvanrossum
gvanrossumhttps://github.com/gvanrossum
on May 30, 2017https://github.com/python/mypy/issues/3470#issuecomment-305032765
https://github.com/ilinum
ilinumhttps://github.com/ilinum
on May 31, 2017https://github.com/python/mypy/issues/3470#issuecomment-305057344
https://github.com/ilinum
ilinumhttps://github.com/ilinum
on May 31, 2017https://github.com/python/mypy/issues/3470#issuecomment-305058284
https://github.com/JukkaL
JukkaLhttps://github.com/JukkaL
on May 31, 2017https://github.com/python/mypy/issues/3470#issuecomment-305285677
https://github.com/ilinum
ilinumhttps://github.com/ilinum
on May 31, 2017https://github.com/python/mypy/issues/3470#issuecomment-305333537
@JukkaLhttps://github.com/JukkaL
ilinumhttps://github.com/ilinum
on Jun 9, 2017https://github.com/python/mypy/issues/3470#event-1118034421
https://github.com/ilinum
ilinumhttps://github.com/ilinum
on Jul 20, 2017https://github.com/python/mypy/issues/3470#issuecomment-316829546
Disallow implicit Any types from Silent Imports #3405https://github.com/python/mypy/pull/3405
Rename --disallow-untyped-defs to --disallow-any=unannotated #3513https://github.com/python/mypy/pull/3513
Option to disallow all expressions of type Any(--disallow-any=expr) #3519https://github.com/python/mypy/pull/3519
Option to disallow explicit Any types (--disallow-any=explicit) #3579https://github.com/python/mypy/pull/3579
Add flag to disallow decorating typed functions with untyped decorators #3536https://github.com/python/mypy/pull/3536
Option to disallow omitting type parameters of generic types #3637https://github.com/python/mypy/pull/3637
ilinumhttps://github.com/ilinum
completedhttps://github.com/python/mypy/issues?q=is%3Aissue%20state%3Aclosed%20archived%3Afalse%20reason%3Acompleted
on Jul 20, 2017https://github.com/python/mypy/issues/3470#event-1172890251
Sign up for freehttps://github.com/signup?return_to=https://github.com/python/mypy/issues/3470
Sign in to commenthttps://github.com/login?return_to=https://github.com/python/mypy/issues/3470
ilinumhttps://github.com/ilinum
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.