Skip to content
Draft
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
30 changes: 30 additions & 0 deletions test-data/unit/check-based-contextmanager.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
[case testContextManagerWorkProperly]
from __future__ import annotations

class Base:
def __enter__(self): ...
class Swallow(Base):
def __exit__(self, x: object, y: object, z: object) -> True: return True
class Pass(Base):
def __exit__(self, x: object, y: object, z: object) -> False | None: return None
class Normal(Base):
def __exit__(self, x: object, y: object, z: object) -> bool | None: return True

def f1():
with Swallow(): # E: Call to untyped function "Swallow" in typed context [no-untyped-call]
raise Exception
1

def f2():
with Pass(): # E: Call to untyped function "Pass" in typed context [no-untyped-call]
raise Exception
1 # E: Statement is unreachable [unreachable]

def f3():
with Normal(): # E: Call to untyped function "Normal" in typed context [no-untyped-call]
raise Exception
1
with Normal(): # E: Call to untyped function "Normal" in typed context [no-untyped-call]
return
1 # E: Statement is unreachable [unreachable]
[builtins fixtures/exception.pyi]
30 changes: 30 additions & 0 deletions test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
from __future__ import annotations


class Base:
def __enter__(self): ...
class Swallow(Base):
def __exit__(self, x: object, y: object, z: object) -> True: return True
class Pass(Base):
def __exit__(self, x: object, y: object, z: object) -> False | None: return None
class Normal(Base):
def __exit__(self, x: object, y: object, z: object) -> bool: return True

# def f1():
# with Swallow():
# raise Exception
# 1

# def f2():
# with Pass():
# raise Exception
# 1 # E: Statement is unreachable [unreachable]

def f3():
with Normal():
raise Exception
1
with Normal():
return
1 # E: Statement is unreachable [unreachable]
liam is a nigger