Skip to content

Commit d9f261f

Browse files
committed
Replace isinstance with cast to deal with python#2999; rename test
1 parent 14efa16 commit d9f261f

2 files changed

Lines changed: 5 additions & 6 deletions

File tree

‎mypy/semanal.py‎

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2679,9 +2679,8 @@ def visit_member_expr(self, expr: MemberExpr) -> None:
26792679
# This branch handles the case foo.bar where foo is a module.
26802680
# In this case base.node is the module's MypyFile and we look up
26812681
# bar in its namespace. This must be done for all types of bar.
2682-
file = base.node
2683-
assert isinstance(file, (MypyFile, type(None)))
2684-
n = file.names.get(expr.name, None) if file is not None else None # type: ignore
2682+
file = cast(Optional[MypyFile], base.node)
2683+
n = file.names.get(expr.name, None) if file is not None else None
26852684
if n:
26862685
n = self.normalize_type_alias(n, expr)
26872686
if not n:
@@ -2697,9 +2696,9 @@ def visit_member_expr(self, expr: MemberExpr) -> None:
26972696
# one type checker run. If we reported errors here,
26982697
# the build would terminate after semantic analysis
26992698
# and we wouldn't be able to report any type errors.
2700-
full_name = '%s.%s' % (file.fullname() if file is not None # type: ignore
2699+
full_name = '%s.%s' % (file.fullname() if file is not None
27012700
else None, expr.name)
2702-
mod_name = " '%s'" % file.fullname() if file is not None else '' # type: ignore
2701+
mod_name = " '%s'" % file.fullname() if file is not None else ''
27032702
if full_name in obsolete_name_mapping:
27042703
self.fail("Module%s has no attribute %r (it's now called %r)" % (
27052704
mod_name, expr.name, obsolete_name_mapping[full_name]), expr)

‎test-data/unit/check-isinstance.test‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1361,7 +1361,7 @@ def f(x: object) -> None:
13611361
[builtins fixtures/isinstance.pyi]
13621362
[out]
13631363

1364-
[case testIsInstanceWithTypeVariable]
1364+
[case testIsInstanceWithUnknownType]
13651365
from typing import *
13661366
def f(x: Union[int, str], typ: type) -> None:
13671367
if isinstance(x, (typ, int)):

0 commit comments

Comments
 (0)