Title: Controlling scope of build options · Issue #1235 · python/mypy · GitHub
Open Graph Title: Controlling scope of build options · Issue #1235 · python/mypy
X Title: Controlling scope of build options · Issue #1235 · python/mypy
Description: Currently the --implicit-any mode flag is global, as it uniformly affects how mypy processes every file in a mypy run. Other global flags are being considered or implemented, including --strict and the "weak mode". Similarly, we could ha...
Open Graph Description: Currently the --implicit-any mode flag is global, as it uniformly affects how mypy processes every file in a mypy run. Other global flags are being considered or implemented, including --strict and...
X Description: Currently the --implicit-any mode flag is global, as it uniformly affects how mypy processes every file in a mypy run. Other global flags are being considered or implemented, including --strict and...
Opengraph URL: https://github.com/python/mypy/issues/1235
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Controlling scope of build options","articleBody":"Currently the `--implicit-any` mode flag is global, as it uniformly affects how mypy processes every file in a mypy run. Other global flags are being considered or implemented, including `--strict` and the \"weak mode\". Similarly, we could have options to disable/enable individual errors/warnings. These kinds of mode flags have some inconvenient properties, and I elaborate on this below.\n\n**A. Combining type checked programs is hard**\n\nIt's hard to combine two independently developed codebases into a single type checked program, as it may be necessary to use the least common denominator options to type check the combined program without spurious warnings. Global flags effectively introduce multiple mypy dialects that aren't quite compatible. Using the least common denominator options is clearly not desirable as programmers likely chose to enable some options for their code for a good reason.\n\nIntegrating multiple pieces of code without loosening type checking may involve a lot of refactoring or adding `# type: ignore` comments.\n\n**B. Migrating to stricter type checking mode is hard**\n\nMigrating from the default mode to `--strict`, for example, would have to be performed for the whole code base to avoid generating warnings. If there is, say, millions of lines code, this can be a huge undertaking, and may require the co-operation of owners of every part of the codebase. It would be much nicer to migrate to stricter options gradually, similar to how mypy supports migration from dynamic to static typing in small increments. This would also give more flexibility to owners of particular modules.\n\n**C. Options aren't self-documenting**\n\nWhen just looking at a source file, it's not obvious under which options it's supposed to type checked. This is less of a problem within a single, uniform codebase, but it becomes more important when combining code from multiple sources. It's easy to \"forget\" that some files should be checked in the strict mode when copying or moving source code, for example, since the knowledge lives in external configuration such as build scripts instead of being close to the physical code.\n\n---\n\nHere are some ways to overcome some of these problems:\n1. We type check code bases with different global options using separate mypy runs, stubbing out dependencies. So if codebases A and B have different global options, and A depends on B, we first type check B using the desired options and generate a set of stub files. We then separately type check A using a different set of options, and using stubs for B. This increases complexity and requires additional tooling to automatically generate stubs. Additionally, this doesn't significantly simplify the migration to stricter options within a single codebase.\n2. Provide fine grained configuration outside source files. For example, perhaps mypy will accept options such as `--strict=package1,package2` that will enforce some options for particular packages only. Alternatively, we could have a configuration file with rules such as `strict=package/**,module`, or perhaps even a hierarchy of such configuration files. This provides more flexibility but it makes it easy to forget to modify the configuration when adding new files or moving files around.\n3. Provide per-file option flags. We always default to some well-defined mode, and we support comments such as `# mypy: strict` near the top of the file that change mode options _for that file only_. This is very flexible and it makes files self-contained, but it's easy to forget to add the desired options to new files. We could also have a tool that enforces that certain options are always used in certain packages, similar to (2) above, in addition to per-file comments.\n4. Don't provide any options. Make the default mode \"good enough\" for most people.\n\nMy proposal is to choose some variant of option 3.\n\n---\n\nNote that I don't consider `--silent-import` a global option because it only affects files _not being processed_, so it's not really problematic in the same sense as the other options I discussed above.\n","author":{"url":"https://github.com/JukkaL","@type":"Person","name":"JukkaL"},"datePublished":"2016-02-23T09:20:53Z","url":"https://github.com/python/mypy/issues/1235"}
| react-profiling | 0 |
| react-import-map | react,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-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:a81b55a6-57e8-911f-ed28-4797c3b02a81 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | AD30:2EC689:29D2FB7:38FAE01:6B004EE0 |
| html-safe-nonce | 5d64fbffd8672d7a77fd474f97c45d93379c8fb4755d0544a17e76cf160fcd1c |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBRDMwOjJFQzY4OToyOUQyRkI3OjM4RkFFMDE6NkIwMDRFRTAiLCJ2aXNpdG9yX2lkIjoiMjk2MTQ0MjUxMjg4MDgxNTg0MCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 339a9e857ccc2f70d19d2782bd62a313109b523171cd39d664aea6da442cbea2 |
| hovercard-subject-tag | issue:135680854 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python/mypy/1235/issue_layout |
| twitter:image | https://opengraph.githubassets.com/c26dc42b10968d934897c812b0f8954d4b367df3f6f868a17de6ff40e1281db9/python/mypy/issues/1235 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/c26dc42b10968d934897c812b0f8954d4b367df3f6f868a17de6ff40e1281db9/python/mypy/issues/1235 |
| og:image:alt | Currently the --implicit-any mode flag is global, as it uniformly affects how mypy processes every file in a mypy run. Other global flags are being considered or implemented, including --strict and... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | JukkaL |
| hostname | github.com |
| expected-hostname | github.com |
| None | f9517bf360d46638a1e5e7daee7158842fe5ef43c9000afa0e127564a7c2f39b |
| turbo-cache-control | no-preview |
| go-import | github.com/python/mypy git https://github.com/python/mypy.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 7053637 |
| octolytics-dimension-repository_nwo | python/mypy |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 7053637 |
| octolytics-dimension-repository_network_root_nwo | python/mypy |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | b27c5dde30676028abd5c5fc53ce5c9b625f8281 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width