diff --git a/.github/mypy-primer-ty.toml b/.github/mypy-primer-ty.toml index 9317364fe2..a64ea72eba 100644 --- a/.github/mypy-primer-ty.toml +++ b/.github/mypy-primer-ty.toml @@ -4,5 +4,6 @@ # Enable off-by-default rules. [rules] possibly-unresolved-reference = "warn" +possibly-missing-import = "warn" unused-ignore-comment = "warn" division-by-zero = "warn" diff --git a/crates/ty/docs/rules.md b/crates/ty/docs/rules.md index 8b35be52a6..6eba48d06a 100644 --- a/crates/ty/docs/rules.md +++ b/crates/ty/docs/rules.md @@ -2511,38 +2511,6 @@ class A: A()[0] # TypeError: 'A' object is not subscriptable ``` -## `possibly-missing-import` - - -Default level: warn · -Added in 0.0.1-alpha.22 · -Related issues · -View source - - - -**What it does** - -Checks for imports of symbols that may be missing. - -**Why is this bad?** - -Importing a missing module or name will raise a `ModuleNotFoundError` -or `ImportError` at runtime. - -**Examples** - -```python -# module.py -import datetime - -if datetime.date.today().weekday() != 6: - a = 1 - -# main.py -from module import a # ImportError: cannot import name 'a' from 'module' -``` - ## `redundant-cast` @@ -2778,6 +2746,38 @@ Dividing by zero raises a `ZeroDivisionError` at runtime. 5 / 0 ``` +## `possibly-missing-import` + + +Default level: ignore · +Added in 0.0.1-alpha.22 · +Related issues · +View source + + + +**What it does** + +Checks for imports of symbols that may be missing. + +**Why is this bad?** + +Importing a missing module or name will raise a `ModuleNotFoundError` +or `ImportError` at runtime. + +**Examples** + +```python +# module.py +import datetime + +if datetime.date.today().weekday() != 6: + a = 1 + +# main.py +from module import a # ImportError: cannot import name 'a' from 'module' +``` + ## `possibly-unresolved-reference` diff --git a/crates/ty_python_semantic/src/types/diagnostic.rs b/crates/ty_python_semantic/src/types/diagnostic.rs index 2dce272e92..165e6b8c3f 100644 --- a/crates/ty_python_semantic/src/types/diagnostic.rs +++ b/crates/ty_python_semantic/src/types/diagnostic.rs @@ -1594,7 +1594,7 @@ declare_lint! { pub(crate) static POSSIBLY_MISSING_IMPORT = { summary: "detects possibly missing imports", status: LintStatus::stable("0.0.1-alpha.22"), - default_level: Level::Warn, + default_level: Level::Ignore, } } diff --git a/crates/ty_server/tests/e2e/snapshots/e2e__commands__debug_command.snap b/crates/ty_server/tests/e2e/snapshots/e2e__commands__debug_command.snap index cf1b0afc64..9be1f13bb1 100644 --- a/crates/ty_server/tests/e2e/snapshots/e2e__commands__debug_command.snap +++ b/crates/ty_server/tests/e2e/snapshots/e2e__commands__debug_command.snap @@ -89,7 +89,6 @@ Settings: Settings { "positional-only-parameter-as-kwarg": Error (Default), "possibly-missing-attribute": Warning (Default), "possibly-missing-implicit-call": Warning (Default), - "possibly-missing-import": Warning (Default), "raw-string-type-annotation": Error (Default), "redundant-cast": Warning (Default), "static-assert-error": Error (Default), diff --git a/ty.schema.json b/ty.schema.json index 183a60dadf..4d53ba776c 100644 --- a/ty.schema.json +++ b/ty.schema.json @@ -926,7 +926,7 @@ "possibly-missing-import": { "title": "detects possibly missing imports", "description": "## What it does\nChecks for imports of symbols that may be missing.\n\n## Why is this bad?\nImporting a missing module or name will raise a `ModuleNotFoundError`\nor `ImportError` at runtime.\n\n## Examples\n```python\n# module.py\nimport datetime\n\nif datetime.date.today().weekday() != 6:\n a = 1\n\n# main.py\nfrom module import a # ImportError: cannot import name 'a' from 'module'\n```", - "default": "warn", + "default": "ignore", "oneOf": [ { "$ref": "#/definitions/Level"