Skip to content

Remove --new-type-inference flag #19570

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 0 additions & 10 deletions mypy/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -1092,10 +1092,6 @@ def add_invertible_flag(
internals_group.add_argument(
"--old-type-inference", action="store_true", help=argparse.SUPPRESS
)
# Deprecated reverse variant of the above.
internals_group.add_argument(
"--new-type-inference", action="store_true", help=argparse.SUPPRESS
)
internals_group.add_argument(
"--disable-expression-cache", action="store_true", help=argparse.SUPPRESS
)
Expand Down Expand Up @@ -1487,12 +1483,6 @@ def set_strict_flags() -> None:
if options.logical_deps:
options.cache_fine_grained = True

if options.new_type_inference:
print(
"Warning: --new-type-inference flag is deprecated;"
" new type inference algorithm is already enabled by default"
)

if options.strict_concatenate and not strict_option_set:
print("Warning: --strict-concatenate is deprecated; use --extra-checks instead")

Expand Down
4 changes: 1 addition & 3 deletions mypy/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -391,10 +391,8 @@ def __init__(self) -> None:
# skip most errors after this many messages have been reported.
# -1 means unlimited.
self.many_errors_threshold = defaults.MANY_ERRORS_THRESHOLD
# Disable new experimental type inference algorithm.
# Disable new type inference algorithm.
self.old_type_inference = False
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we still need this one? There are only a couple of use sites remaining, maybe just axe them here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, no, I think we may keep it for a while more (just in case), since it is not a no-op, unlike --new-type-inference.

# Deprecated reverse version of the above, do not use.
self.new_type_inference = False
# Disable expression cache (for debugging).
self.disable_expression_cache = False
# Export line-level, limited, fine-grained dependency information in cache data
Expand Down
35 changes: 0 additions & 35 deletions test-data/unit/check-generics.test
Original file line number Diff line number Diff line change
Expand Up @@ -2750,7 +2750,6 @@ reveal_type(func(1)) # N: Revealed type is "builtins.int"
[builtins fixtures/tuple.pyi]

[case testGenericLambdaGenericMethodNoCrash]
# flags: --new-type-inference
from typing import TypeVar, Union, Callable, Generic

S = TypeVar("S")
Expand Down Expand Up @@ -2789,7 +2788,6 @@ reveal_type(dict2) # N: Revealed type is "builtins.dict[Any, __main__.B]"
-- ------------------------------------------------------------------

[case testInferenceAgainstGenericCallable]
# flags: --new-type-inference
from typing import TypeVar, Callable, List

X = TypeVar('X')
Expand All @@ -2807,7 +2805,6 @@ reveal_type(bar(id)) # N: Revealed type is "builtins.list[builtins.int]"
[builtins fixtures/list.pyi]

[case testInferenceAgainstGenericCallableNoLeak]
# flags: --new-type-inference
from typing import TypeVar, Callable

T = TypeVar('T')
Expand All @@ -2823,7 +2820,6 @@ reveal_type(f(tpl)) # N: Revealed type is "Any"
[out]

[case testInferenceAgainstGenericCallableChain]
# flags: --new-type-inference
from typing import TypeVar, Callable, List

X = TypeVar('X')
Expand All @@ -2836,7 +2832,6 @@ reveal_type(chain(id, id)) # N: Revealed type is "def (builtins.int) -> builtin
[builtins fixtures/list.pyi]

[case testInferenceAgainstGenericCallableGeneric]
# flags: --new-type-inference
from typing import TypeVar, Callable, List

S = TypeVar('S')
Expand All @@ -2857,7 +2852,6 @@ reveal_type(same(42)) # N: Revealed type is "builtins.list[builtins.int]"
[builtins fixtures/list.pyi]

[case testInferenceAgainstGenericCallableGenericReverse]
# flags: --new-type-inference
from typing import TypeVar, Callable, List

S = TypeVar('S')
Expand All @@ -2878,7 +2872,6 @@ reveal_type(same([42])) # N: Revealed type is "builtins.int"
[builtins fixtures/list.pyi]

[case testInferenceAgainstGenericCallableGenericArg]
# flags: --new-type-inference
from typing import TypeVar, Callable, List

S = TypeVar('S')
Expand All @@ -2899,7 +2892,6 @@ reveal_type(single(42)) # N: Revealed type is "builtins.list[builtins.int]"
[builtins fixtures/list.pyi]

[case testInferenceAgainstGenericCallableGenericChain]
# flags: --new-type-inference
from typing import TypeVar, Callable, List

S = TypeVar('S')
Expand All @@ -2913,7 +2905,6 @@ reveal_type(comb(id, id)) # N: Revealed type is "def [T] (T`1) -> T`1"
[builtins fixtures/list.pyi]

[case testInferenceAgainstGenericCallableGenericNonLinear]
# flags: --new-type-inference
from typing import TypeVar, Callable, List

S = TypeVar('S')
Expand All @@ -2934,7 +2925,6 @@ reveal_type(mix([id, id, id])) # N: Revealed type is "def [S] (S`4) -> builtins
[builtins fixtures/list.pyi]

[case testInferenceAgainstGenericCurry]
# flags: --new-type-inference
from typing import Callable, List, TypeVar

S = TypeVar("S")
Expand All @@ -2953,7 +2943,6 @@ reveal_type(dec2(test2)) # N: Revealed type is "def [T] (T`3) -> def (T`3) -> T
[builtins fixtures/list.pyi]

[case testInferenceAgainstGenericCallableNewVariable]
# flags: --new-type-inference
from typing import TypeVar, Callable, List

S = TypeVar('S')
Expand All @@ -2968,7 +2957,6 @@ reveal_type(dec(test)) # N: Revealed type is "def [U] (builtins.list[U`-1]) ->
[builtins fixtures/list.pyi]

[case testInferenceAgainstGenericCallableGenericAlias]
# flags: --new-type-inference
from typing import TypeVar, Callable, List

S = TypeVar('S')
Expand All @@ -2986,7 +2974,6 @@ reveal_type(dec(id)) # N: Revealed type is "def [S] (S`1) -> builtins.list[S`1]
[builtins fixtures/list.pyi]

[case testInferenceAgainstGenericCallableGenericProtocol]
# flags: --new-type-inference
from typing import TypeVar, Protocol, Generic, Optional

T = TypeVar('T')
Expand All @@ -3002,7 +2989,6 @@ reveal_type(lift(g)) # N: Revealed type is "def [T] (Union[T`1, None]) -> Union
[builtins fixtures/list.pyi]

[case testInferenceAgainstGenericSplitOrder]
# flags: --new-type-inference
from typing import TypeVar, Callable, List

S = TypeVar('S')
Expand All @@ -3017,7 +3003,6 @@ reveal_type(dec(id, id)) # N: Revealed type is "def (builtins.int) -> builtins.
[builtins fixtures/list.pyi]

[case testInferenceAgainstGenericSplitOrderGeneric]
# flags: --new-type-inference
from typing import TypeVar, Callable, Tuple

S = TypeVar('S')
Expand Down Expand Up @@ -3048,7 +3033,6 @@ reveal_type(id) # N: Revealed type is "def (builtins.int) -> builtins.int"
[builtins fixtures/tuple.pyi]

[case testInferenceAgainstGenericEllipsisSelfSpecialCase]
# flags: --new-type-inference
from typing import Self, Callable, TypeVar

T = TypeVar("T")
Expand All @@ -3062,7 +3046,6 @@ c: C
reveal_type(c.test()) # N: Revealed type is "__main__.C"

[case testInferenceAgainstGenericBoundsAndValues]
# flags: --new-type-inference
from typing import TypeVar, Callable, List

class B: ...
Expand Down Expand Up @@ -3090,7 +3073,6 @@ reveal_type(dec2(id2)) # N: Revealed type is "def (Never) -> builtins.list[Neve
# E: Argument 1 to "dec2" has incompatible type "Callable[[V], V]"; expected "Callable[[Never], Never]"

[case testInferenceAgainstGenericLambdas]
# flags: --new-type-inference
from typing import TypeVar, Callable, List

S = TypeVar('S')
Expand Down Expand Up @@ -3127,7 +3109,6 @@ dec4_bound(lambda x: x) # E: Value of type variable "I" of "dec4_bound" cannot
[builtins fixtures/list.pyi]

[case testInferenceAgainstGenericParamSpecBasicInList]
# flags: --new-type-inference
from typing import TypeVar, Callable, List, Tuple
from typing_extensions import ParamSpec

Expand All @@ -3146,7 +3127,6 @@ reveal_type(dec(pair)) # N: Revealed type is "def [U, V] (x: U`-1, y: V`-2) ->
[builtins fixtures/list.pyi]

[case testInferenceAgainstGenericParamSpecBasicDeList]
# flags: --new-type-inference
from typing import TypeVar, Callable, List, Tuple
from typing_extensions import ParamSpec

Expand All @@ -3163,7 +3143,6 @@ reveal_type(dec(either)) # N: Revealed type is "def [T] (x: builtins.list[T`5],
[builtins fixtures/list.pyi]

[case testInferenceAgainstGenericParamSpecPopOff]
# flags: --new-type-inference
from typing import TypeVar, Callable, List, Tuple
from typing_extensions import ParamSpec, Concatenate

Expand All @@ -3184,7 +3163,6 @@ reveal_type(dec(dec)) # N: Revealed type is "def () -> def [T, P, S] (def (T`-1
[builtins fixtures/list.pyi]

[case testInferenceAgainstGenericParamSpecPopOn]
# flags: --new-type-inference
from typing import TypeVar, Callable, List, Tuple
from typing_extensions import ParamSpec, Concatenate

Expand All @@ -3206,7 +3184,6 @@ reveal_type(dec(dec)) # N: Revealed type is "def [T, S] (T`13, f: def () -> def
[builtins fixtures/list.pyi]

[case testInferenceAgainstGenericParamSpecVsParamSpec]
# flags: --new-type-inference
from typing import TypeVar, Callable, List, Tuple, Generic
from typing_extensions import ParamSpec, Concatenate

Expand All @@ -3227,7 +3204,6 @@ reveal_type(dec(h)) # N: Revealed type is "def [T, Q] (T`-1, *Q.args, **Q.kwarg
[builtins fixtures/list.pyi]

[case testInferenceAgainstGenericParamSpecVsParamSpecConcatenate]
# flags: --new-type-inference
from typing import TypeVar, Callable, List, Tuple, Generic
from typing_extensions import ParamSpec, Concatenate

Expand All @@ -3245,7 +3221,6 @@ reveal_type(dec(h)) # N: Revealed type is "def [T, Q] (T`-1, *Q.args, **Q.kwarg
[builtins fixtures/list.pyi]

[case testInferenceAgainstGenericParamSpecSecondary]
# flags: --new-type-inference
from typing import TypeVar, Callable, List, Tuple, Generic
from typing_extensions import ParamSpec, Concatenate

Expand All @@ -3263,7 +3238,6 @@ reveal_type(dec(g)) # N: Revealed type is "def (builtins.int) -> __main__.Foo[[
[builtins fixtures/list.pyi]

[case testInferenceAgainstGenericParamSpecSecondOrder]
# flags: --new-type-inference
from typing import TypeVar, Callable
from typing_extensions import ParamSpec, Concatenate

Expand All @@ -3285,7 +3259,6 @@ reveal_type(transform(dec2)) # N: Revealed type is "def [W, T] (def (builtins.i
[builtins fixtures/tuple.pyi]

[case testNoAccidentalVariableClashInNestedGeneric]
# flags: --new-type-inference
from typing import TypeVar, Callable, Generic, Tuple

T = TypeVar('T')
Expand All @@ -3302,7 +3275,6 @@ def apply(a: S, b: T) -> None:
[builtins fixtures/tuple.pyi]

[case testInferenceAgainstGenericParamSpecSpuriousBoundsNotUsed]
# flags: --new-type-inference
from typing import TypeVar, Callable, Generic
from typing_extensions import ParamSpec, Concatenate

Expand All @@ -3321,7 +3293,6 @@ reveal_type(test) # N: Revealed type is "def () -> def [Q] (__main__.Foo[Q`-1])
[builtins fixtures/tuple.pyi]

[case testInferenceAgainstGenericVariadicBasicInList]
# flags: --new-type-inference
from typing import Tuple, TypeVar, List, Callable
from typing_extensions import Unpack, TypeVarTuple

Expand All @@ -3341,7 +3312,6 @@ reveal_type(dec(pair)) # N: Revealed type is "def [U, V] (U`-1, V`-2) -> builti
[builtins fixtures/tuple.pyi]

[case testInferenceAgainstGenericVariadicBasicDeList]
# flags: --new-type-inference
from typing import Tuple, TypeVar, List, Callable
from typing_extensions import Unpack, TypeVarTuple

Expand All @@ -3359,7 +3329,6 @@ reveal_type(dec(either)) # N: Revealed type is "def [T] (builtins.list[T`5], bu
[builtins fixtures/tuple.pyi]

[case testInferenceAgainstGenericVariadicPopOff]
# flags: --new-type-inference
from typing import TypeVar, Callable, List, Tuple
from typing_extensions import Unpack, TypeVarTuple

Expand All @@ -3381,7 +3350,6 @@ reveal_type(dec(dec)) # N: Revealed type is "def () -> def [T, Ts, S] (def (T`-
[builtins fixtures/list.pyi]

[case testInferenceAgainstGenericVariadicPopOn]
# flags: --new-type-inference
from typing import TypeVar, Callable, List, Tuple
from typing_extensions import Unpack, TypeVarTuple

Expand All @@ -3404,7 +3372,6 @@ reveal_type(dec(dec)) # N: Revealed type is "def [T, S] (T`13, def () -> def (T
[builtins fixtures/list.pyi]

[case testInferenceAgainstGenericVariadicVsVariadic]
# flags: --new-type-inference
from typing import TypeVar, Callable, List, Generic
from typing_extensions import Unpack, TypeVarTuple

Expand All @@ -3424,7 +3391,6 @@ reveal_type(dec(g)) # N: Revealed type is "def [Ts] (*Unpack[Ts`4]) -> builtins
[builtins fixtures/list.pyi]

[case testInferenceAgainstGenericVariadicVsVariadicConcatenate]
# flags: --new-type-inference
from typing import TypeVar, Callable, Generic
from typing_extensions import Unpack, TypeVarTuple

Expand All @@ -3443,7 +3409,6 @@ reveal_type(dec(h)) # N: Revealed type is "def [T, Us] (T`-1, *Unpack[Us`-2]) -
[builtins fixtures/list.pyi]

[case testInferenceAgainstGenericVariadicSecondary]
# flags: --new-type-inference
from typing import TypeVar, Callable, Generic
from typing_extensions import Unpack, TypeVarTuple

Expand Down
1 change: 0 additions & 1 deletion test-data/unit/check-inference-context.test
Original file line number Diff line number Diff line change
Expand Up @@ -693,7 +693,6 @@ f(lambda: None)
g(lambda: None)

[case testIsinstanceInInferredLambda]
# flags: --new-type-inference
from typing import TypeVar, Callable, Optional
T = TypeVar('T')
S = TypeVar('S')
Expand Down
2 changes: 0 additions & 2 deletions test-data/unit/check-inference.test
Original file line number Diff line number Diff line change
Expand Up @@ -1405,14 +1405,12 @@ class B: pass
[builtins fixtures/list.pyi]

[case testUninferableLambda]
# flags: --new-type-inference
from typing import TypeVar, Callable
X = TypeVar('X')
def f(x: Callable[[X], X]) -> X: pass
y = f(lambda x: x) # E: Need type annotation for "y"

[case testUninferableLambdaWithTypeError]
# flags: --new-type-inference
from typing import TypeVar, Callable
X = TypeVar('X')
def f(x: Callable[[X], X], y: str) -> X: pass
Expand Down
1 change: 0 additions & 1 deletion test-data/unit/check-overloading.test
Original file line number Diff line number Diff line change
Expand Up @@ -6637,7 +6637,6 @@ reveal_type(Snafu.snafu('123')) # N: Revealed type is "builtins.str"
[builtins fixtures/staticmethod.pyi]

[case testOverloadedWithInternalTypeVars]
# flags: --new-type-inference
import m

[file m.pyi]
Expand Down
4 changes: 0 additions & 4 deletions test-data/unit/check-parameter-specification.test
Original file line number Diff line number Diff line change
Expand Up @@ -1121,7 +1121,6 @@ reveal_type(jf(1)) # N: Revealed type is "None"
[builtins fixtures/paramspec.pyi]

[case testGenericsInInferredParamspecReturn]
# flags: --new-type-inference
from typing import Callable, TypeVar, Generic
from typing_extensions import ParamSpec

Expand Down Expand Up @@ -1646,7 +1645,6 @@ def f(f: Callable[P, None], *args: P.args, **kwargs: P.kwargs) -> None: ...
[builtins fixtures/paramspec.pyi]

[case testParamSpecDecoratorAppliedToGeneric]
# flags: --new-type-inference
from typing import Callable, List, TypeVar
from typing_extensions import ParamSpec

Expand Down Expand Up @@ -1684,7 +1682,6 @@ reveal_type(test(*ints)) # N: Revealed type is "__main__.Foo[[*builtins.int]]"
[builtins fixtures/paramspec.pyi]

[case testParamSpecArgumentParamInferenceGeneric]
# flags: --new-type-inference
from typing import Callable, TypeVar
from typing_extensions import ParamSpec

Expand All @@ -1702,7 +1699,6 @@ y: int = call(identity, 2)
[builtins fixtures/paramspec.pyi]

[case testParamSpecNestedApplyNoCrash]
# flags: --new-type-inference
from typing import Callable, TypeVar
from typing_extensions import ParamSpec

Expand Down
1 change: 0 additions & 1 deletion test-data/unit/check-plugin-attrs.test
Original file line number Diff line number Diff line change
Expand Up @@ -1201,7 +1201,6 @@ class A:
[builtins fixtures/bool.pyi]

[case testAttrsFactoryBadReturn]
# flags: --new-type-inference
import attr
def my_factory() -> int:
return 7
Expand Down
1 change: 0 additions & 1 deletion test-data/unit/check-typevar-tuple.test
Original file line number Diff line number Diff line change
Expand Up @@ -886,7 +886,6 @@ reveal_type(z) # N: Revealed type is "tuple[builtins.int, Unpack[builtins.tuple
[builtins fixtures/tuple.pyi]

[case testInferenceAgainstGenericVariadicWithBadType]
# flags: --new-type-inference
from typing import TypeVar, Callable, Generic
from typing_extensions import Unpack, TypeVarTuple

Expand Down
Loading
Loading