8000 Fix inference logic for isinstance by pkch · Pull Request #2997 · python/mypy · GitHub
[go: up one dir, main page]

Skip to content

Fix inference logic for isinstance #2997

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 8 commits into from
Mar 19, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Add unit test
  • Loading branch information
pkch committed Mar 19, 2017
commit 14efa1639b50bce05052b36c5abdd3e6a8189aad
8 changes: 8 additions & 0 deletions test-data/unit/check-isinstance.test
Original file line number Diff line number Diff line change
Expand Up @@ -1360,3 +1360,11 @@ def f(x: object) -> None:
reveal_type(b) # E: Revealed type is '__main__.A'
[builtins fixtures/isinstance.pyi]
[out]

[case testIsInstanceWithTypeVariable]
from typing import *
def f(x: Union[int, str], typ: type) -> None:
if isinstance(x, (typ, int)):
x + 1 # E: Unsupported operand types for + (likely involving Union)
8000 Copy link
Collaborator

Choose a reason for hiding this comment

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

Add also an else: block and do a reveal_type(x) in that block. Add another reveal_type(x) just after the if statement.

[builtins fixtures/isinstancelist.pyi]
Copy link
Collaborator

Choose a reason for hiding this comment

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

Not directly related, but can you add a test case that does something like isinstance(x, ())?


Copy link
Collaborator

Choose a reason for hiding this comment

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

Add test for the type object that is Type[A] or similar. Example:

class A: pass

def f(x: Union[int, A], a: Type[A]) -> None:
    if isinstance(x, a):
        reveal_type(x)
    elif isinstance(x, int):
        reveal_type(x)
    else:
        reveal_type(x)
    reveal_type(x)

2 changes: 1 addition & 1 deletion typeshed
Submodule typeshed updated 88 files
+2 −2 .travis.yml
+0 −1 CONTRIBUTING.md
+5 −5 requirements-tests-py3.txt
+11 −11 stdlib/2/ConfigParser.pyi
+21 −22 stdlib/2/__builtin__.pyi
+20 −20 stdlib/2/array.pyi
+10 −12 stdlib/2/codecs.pyi
+5 −8 stdlib/2/compileall.pyi
+9 −6 stdlib/2/datetime.pyi
+3 −3 stdlib/2/encodings/utf_8.pyi
+5 −5 stdlib/2/pickle.pyi
+1 −3 stdlib/2/socket.pyi
+2 −2 stdlib/2/spwd.pyi
+3 −3 stdlib/2/tempfile.pyi
+1 −1 stdlib/2/types.pyi
+40 −0 stdlib/2/unicodedata.pyi
+7 −7 stdlib/2and3/_bisect.pyi
+1 −1 stdlib/2and3/asynchat.pyi
+1 −1 stdlib/2and3/asyncore.pyi
+3 −3 stdlib/2and3/fractions.pyi
+0 −134 stdlib/2an 10000 d3/ftplib.pyi
+3 −3 stdlib/2and3/logging/__init__.pyi
+1 −1 stdlib/2and3/logging/handlers.pyi
+2 −2 stdlib/2and3/opcode.pyi
+0 −38 stdlib/2and3/unicodedata.pyi
+28 −65 stdlib/3.4/asyncio/events.pyi
+5 −5 stdlib/3.4/asyncio/locks.pyi
+8 −8 stdlib/3.4/asyncio/queues.pyi
+1 −1 stdlib/3.4/asyncio/tasks.pyi
+2 −2 stdlib/3.4/pathlib.pyi
+0 −24 stdlib/3.4/statistics.pyi
+1 −1 stdlib/3/_markupbase.pyi
+4 −5 stdlib/3/_posixsubprocess.pyi
+1 −1 stdlib/3/base64.pyi
+20 −24 stdlib/3/builtins.pyi
+1 −1 stdlib/3/calendar.pyi
+194 −0 stdlib/3/codecs.pyi
+12 −13 stdlib/3/collections/__init__.pyi
+0 −18 stdlib/3/compileall.pyi
+1 −1 stdlib/3/datetime.pyi
+1 −1 stdlib/3/difflib.pyi
+45 −47 stdlib/3/dis.pyi
+1 −1 stdlib/3/email/message.pyi
+3 −3 stdlib/3/encodings/utf_8.pyi
+2 −3 stdlib/3/http/client.pyi
+1 −1 stdlib/3/inspect.pyi
+2 −2 stdlib/3/json.pyi
+3 −3 stdlib/3/linecache.pyi
+0 −6 stdlib/3/os/__init__.pyi
+1 −1 stdlib/3/queue.pyi
+2 −2 stdlib/3/shlex.pyi
+1 −3 stdlib/3/socket.pyi
+2 −0 stdlib/3/ssl.pyi
+41 −87 stdlib/3/subprocess.pyi
+39 −78 stdlib/3/tempfile.pyi
+3 −3 stdlib/3/token.pyi
+17 −30 stdlib/3/tokenize.pyi
+1 −1 stdlib/3/types.pyi
+5 −12 stdlib/3/typing.pyi
+37 −0 stdlib/3/unicodedata.pyi
+17 −18 stdlib/3/unittest/__init__.pyi
+2 −3 stdlib/3/urllib/parse.pyi
+2 −2 third_party/2/concurrent/futures/__init__.pyi
+1 −1 third_party/2/requests/packages/urllib3/connection.pyi
+1 −1 third_party/2/requests/packages/urllib3/packages/ssl_match_hostname/__init__.pyi
+55 −62 third_party/2/werkzeug/wrappers.pyi
+2 −2 third_party/2and3/characteristic/__init__.pyi
+2 −2 third_party/2and3/mypy_extensions.pyi
+5 −5 third_party/3.6/click/core.pyi
+13 −13 third_party/3.6/click/decorators.pyi
+4 −4 third_party/3.6/click/termui.pyi
+11 −11 third_party/3.6/click/types.pyi
+4 −4 third_party/3.6/click/utils.pyi
+4 −4 third_party/3/dateutil/parser.pyi
+2 −2 third_party/3/dateutil/relativedelta.pyi
+1 −1 third_party/3/dateutil/tz/_common.pyi
+1 −1 third_party/3/dateutil/tz/tz.pyi
+48 −49 third_party/3/itsdangerous.pyi
+24 −24 third_party/3/lxml/etree.pyi
+4 −4 third_party/3/requests/adapters.pyi
+17 −17 third_party/3/requests/api.pyi
+4 −6 third_party/3/requests/cookies.pyi
+4 −4 third_party/3/requests/models.pyi
+6 −13 third_party/3/requests/packages/urllib3/connection.pyi
+4 −2 third_party/3/requests/packages/urllib3/response.pyi
+22 −24 third_party/3/requests/sessions.pyi
+3 −3 third_party/3/requests/structures.pyi
+55 −62 third_party/3/werkzeug/wrappers.pyi
0