Fix call type for open functions (PY-16893, PY-16894, PY-26313)

This commit is contained in:
Semyon Proshev
2017-11-14 14:32:54 +03:00
parent 46da603b07
commit eb5094feda
14 changed files with 135 additions and 81 deletions
@@ -0,0 +1,9 @@
from foo import calcT, calcB
with open('1.txt') as file1:
calcT(<warning descr="Expected type 'TextIO', got 'BinaryIO' instead">file1</warning>)
calcB(file1)
with open('1.txt', 'rb') as file2:
calcT(<warning descr="Expected type 'TextIO', got 'BinaryIO' instead">file2</warning>)
calcB(file2)
@@ -0,0 +1,2 @@
def calcT(a): pass
def calcB(a): pass
@@ -0,0 +1,5 @@
from typing import BinaryIO, TextIO
def calcT(a: TextIO) -> int: ...
def calcB(a: BinaryIO) -> int: ...
@@ -0,0 +1,9 @@
from foo import calcT, calcB
with open('1.txt') as file1:
calcT(file1)
calcB(<warning descr="Expected type 'BinaryIO', got 'TextIO' instead">file1</warning>)
with open('1.txt', 'rb') as file2:
calcT(<warning descr="Expected type 'TextIO', got 'BinaryIO' instead">file2</warning>)
calcB(file2)
@@ -0,0 +1,2 @@
def calcT(a): pass
def calcB(a): pass
@@ -0,0 +1,5 @@
from typing import BinaryIO, TextIO
def calcT(a: TextIO) -> int: ...
def calcB(a: BinaryIO) -> int: ...
@@ -2,4 +2,4 @@ with open('foo', 'wb') as fd:
fd.write(b'bar')
with open('foo', 'wb') as fd:
fd.write(<warning descr="Expected type 'Union[bytes, bytearray]', got 'str' instead">'bar'</warning>)
fd.write(<warning descr="Unexpected type(s):(str)Possible types:(bytes)(bytearray)">'bar'</warning>)
@@ -1,7 +1,7 @@
f = open("file.txt")
f.writelines("a") # OK
f.<warning descr="Unresolved attribute reference 'writeliness' for class 'file'">writeliness</warning>("a")
f.<warning descr="Unresolved attribute reference 'writeliness' for class 'BinaryIO'">writeliness</warning>("a")
f = open("file.txt", "rb")
f.writelines("a") # OK
f.<warning descr="Unresolved attribute reference 'writeliness' for class 'file'">writeliness</warning>("a")
f.<warning descr="Unresolved attribute reference 'writeliness' for class 'BinaryIO'">writeliness</warning>("a")