Title: Redesign import handling · Issue #8584 · python/mypy · GitHub
Open Graph Title: Redesign import handling · Issue #8584 · python/mypy
X Title: Redesign import handling · Issue #8584 · python/mypy
Description: The way mypy deals with imports is quite confusing. I'm proposing that we reconsider how various import-related features work. There are existing issues that cover some of these, but I want to discuss the changes in a central location he...
Open Graph Description: The way mypy deals with imports is quite confusing. I'm proposing that we reconsider how various import-related features work. There are existing issues that cover some of these, but I want to disc...
X Description: The way mypy deals with imports is quite confusing. I'm proposing that we reconsider how various import-related features work. There are existing issues that cover some of these, but I want to ...
Opengraph URL: https://github.com/python/mypy/issues/8584
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Redesign import handling ","articleBody":"The way mypy deals with imports is quite confusing. I'm proposing that we reconsider how various import-related features work. There are existing issues that cover some of these, but I want to discuss the changes in a central location here, since many of these are related. \r\n\r\nI'd love to hear what everybody thinks about this proposal! My idea is that all (or most) of the changes below would be implemented as part of a big overhaul, though likely not in a single mypy release. I think that the current situation is sufficiently problematic that small incremental changes aren't enough.\r\n\r\n**1. Enable namespace packages by default**\r\n\r\nMypy would support namespace packages by default. Currently `--namespace-packages` is needed, which is confusing for new users, in particular.\r\n\r\n**2. Generalize specifying namespace packages on the command line**\r\n\r\nAllow passing namespace packages using all the supported ways of specifying which files to type check on the command line. (See also #5759.)\r\n\r\n**3. Require package roots to be explicitly specified**\r\n\r\nTo support namespace packages properly, the way mypy currently infers module name from a source file path by looking for `__init__.py` files can't be used, since namespace packages don't contain `__init__.py` files. Instead, all package roots would need to be explicitly defined using the mypy module search path. Some package roots will be enabled by default, such as the current directory and typeshed stub directories.\r\n\r\nWe may want to tweak how the module search path is specified, since many additional users might need to use it.\r\n\r\n**4. Use modular typeshed, and don't ship (most) third party package stubs with mypy**\r\n\r\nThis is unrelated to namespace packages, but will be essential to allow typeshed to grow significantly. As third-party stubs would now be installed as packages, this would also make PEP-561 and non-PEP-561 packages behave closer to each other (for both you'll have to install some package first). Currently PEP 561 packages require a very different workflow, which is confusing.\r\n\r\nThis assumes that we'll actually switch to a modular typeshed. I'm hoping that we'll make progress in the next few months.\r\n\r\n**5. Allow selectively processing arbitrary installed packages**\r\n\r\nMake it possible to opt-in to type checking individual installed packages, even if they don't support PEP 561. This was proposed in #8545. This would be make it easier to get basic support for many third party packages that don't have stubs and don't support PEP 561.\r\n\r\nThis isn't enabled by default since some packages won't work properly or at all (C extensions, for example). One option would be disallow this option by default for popular packages with known issues.\r\n\r\n**6. Rethink import related error messages**\r\n\r\nTypical import related error messages should give explicit instructions about how to solve the issue. Ignoring missing imports should rarely be needed, and not recommended in the documentation. Examples of what might be suggested:\r\n\r\n* Install stub package `\u003cpackage>` (this will be particularly important once we move to modular typeshed)\r\n* Install package `\u003cpackage>` (in case it's known to support PEP 561)\r\n* Give the command line options that allow using an installed package (in case stubs don't exist, but the package is importable)\r\n* Update the module search path (if it doesn't look like a third-party library module)\r\n\r\n**7. Add flag to use the old module name inference behavior**\r\n\r\nProvide a backward compatibility option to use the old behavior of inferring module names, as migrating from the old behavior can be non-trivial for large projects. Still, the key of this proposal is that the new, backward incompatible behavior will be enabled by default, and should be used by most users.\r\n","author":{"url":"https://github.com/JukkaL","@type":"Person","name":"JukkaL"},"datePublished":"2020-03-25T14:09:48Z","url":"https://github.com/python/mypy/issues/8584"}
| 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:0c4ab738-7070-b898-d061-a2e5cc907faf |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | E544:26206F:2D7D3B2:3BF0A9D:6B001DFB |
| html-safe-nonce | eacc150ef53bc945017a3977c449ffbb18f0a79d023bbcf753f84b290b6f9a1f |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFNTQ0OjI2MjA2RjoyRDdEM0IyOjNCRjBBOUQ6NkIwMDFERkIiLCJ2aXNpdG9yX2lkIjoiMzU1ODAxNTU2NjIzOTI0Mzc3MSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 62eaeece37e61a0882bd92e4da54cdb5980d574810597b7ef4081a4d625be441 |
| hovercard-subject-tag | issue:587723993 |
| 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/8584/issue_layout |
| twitter:image | https://opengraph.githubassets.com/7ee33fd541e3ed058ea92305da420bae0a6ca780bc876c7819918a0adc591149/python/mypy/issues/8584 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/7ee33fd541e3ed058ea92305da420bae0a6ca780bc876c7819918a0adc591149/python/mypy/issues/8584 |
| og:image:alt | The way mypy deals with imports is quite confusing. I'm proposing that we reconsider how various import-related features work. There are existing issues that cover some of these, but I want to disc... |
| 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 | 4eb4cba0d69f045374ac15de9666d22b0961e1d555cc3824f36b7734c00c78e0 |
| 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 | 44c658b24abf00491fb7ae5f56d42c9f38cbeab2 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width