mirror of
https://github.com/microsoft/pyright.git
synced 2024-07-14 11:00:25 +03:00
Fixed bug that results in incorrect type isinstance
or issubclass
type narrowing when using a type variable with an upper bound that includes a promotion type. This addresses #8238. (#8243)
This commit is contained in:
parent
427ca1143e
commit
05726120ad
@ -1764,7 +1764,11 @@ function narrowTypeForIsInstanceInternal(
|
|||||||
|
|
||||||
const filteredType = evaluator.mapSubtypesExpandTypeVars(
|
const filteredType = evaluator.mapSubtypesExpandTypeVars(
|
||||||
expandedTypes,
|
expandedTypes,
|
||||||
/* options */ undefined,
|
{
|
||||||
|
expandCallback: (type) => {
|
||||||
|
return evaluator.expandPromotionTypes(errorNode, type);
|
||||||
|
},
|
||||||
|
},
|
||||||
(subtype, unexpandedSubtype) => {
|
(subtype, unexpandedSubtype) => {
|
||||||
// If we fail to filter anything in the negative case, we need to decide
|
// If we fail to filter anything in the negative case, we need to decide
|
||||||
// whether to retain the original TypeVar or replace it with its specialized
|
// whether to retain the original TypeVar or replace it with its specialized
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
# pyright: reportUnnecessaryIsInstance=true
|
# pyright: reportUnnecessaryIsInstance=true
|
||||||
|
|
||||||
from typing import Union
|
from typing import TypeVar, Union
|
||||||
|
|
||||||
# This should generate an error because "dummy" can't be resolved.
|
# This should generate an error because "dummy" can't be resolved.
|
||||||
# The symbol Document should have an unknown type.
|
# The symbol Document should have an unknown type.
|
||||||
@ -33,3 +33,13 @@ def func3(obj: float):
|
|||||||
reveal_type(obj, expected_text="float")
|
reveal_type(obj, expected_text="float")
|
||||||
else:
|
else:
|
||||||
reveal_type(obj, expected_text="int")
|
reveal_type(obj, expected_text="int")
|
||||||
|
|
||||||
|
|
||||||
|
T = TypeVar("T", bound=float)
|
||||||
|
|
||||||
|
|
||||||
|
def func4(t: type[T]):
|
||||||
|
if issubclass(t, float):
|
||||||
|
reveal_type(t, expected_text="type[float]*")
|
||||||
|
else:
|
||||||
|
reveal_type(t, expected_text="type[int]*")
|
||||||
|
Loading…
Reference in New Issue
Block a user