Skip to content

Commit f51d61b

Browse files
committed
Improve signature of __exit__
1 parent bb6eda8 commit f51d61b

File tree

5 files changed

+40
-12
lines changed

5 files changed

+40
-12
lines changed

bpython/curtsiesfrontend/_internal.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@
2121
# THE SOFTWARE.
2222

2323
import pydoc
24+
from types import TracebackType
25+
from typing import Optional, Literal, Type
26+
2427
from .. import _internal
2528

2629

@@ -29,8 +32,14 @@ def __enter__(self):
2932
self._orig_pager = pydoc.pager
3033
pydoc.pager = self
3134

32-
def __exit__(self, *args):
35+
def __exit__(
36+
self,
37+
exc_type: Optional[Type[BaseException]],
38+
exc_val: Optional[BaseException],
39+
exc_tb: Optional[TracebackType],
40+
) -> Literal[False]:
3341
pydoc.pager = self._orig_pager
42+
return False
3443

3544
def __call__(self, text):
3645
return None

bpython/curtsiesfrontend/repl.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
import time
1313
import unicodedata
1414
from enum import Enum
15-
16-
from typing import Dict, Any, List, Optional, Tuple, Union, cast
15+
from types import TracebackType
16+
from typing import Dict, Any, List, Optional, Tuple, Union, cast, Literal, Type
1717

1818
import blessings
1919
import greenlet
@@ -573,7 +573,12 @@ def __enter__(self):
573573
sitefix.monkeypatch_quit()
574574
return self
575575

576-
def __exit__(self, *args):
576+
def __exit__(
577+
self,
578+
exc_type: Optional[Type[BaseException]],
579+
exc_val: Optional[BaseException],
580+
exc_tb: Optional[TracebackType],
581+
) -> Literal[False]:
577582
sys.stdin = self.orig_stdin
578583
sys.stdout = self.orig_stdout
579584
sys.stderr = self.orig_stderr
@@ -584,6 +589,7 @@ def __exit__(self, *args):
584589
signal.signal(signal.SIGTSTP, self.orig_sigtstp_handler)
585590

586591
sys.meta_path = self.orig_meta_path
592+
return False
587593

588594
def sigwinch_handler(self, signum, frame):
589595
old_rows, old_columns = self.height, self.width

bpython/filelock.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2121
# THE SOFTWARE.
2222

23-
from typing import Optional, Type, IO
23+
from typing import Optional, Type, IO, Literal
2424
from types import TracebackType
2525

2626
has_fcntl = True
@@ -59,9 +59,10 @@ def __exit__(
5959
exc_type: Optional[Type[BaseException]],
6060
exc: Optional[BaseException],
6161
exc_tb: Optional[TracebackType],
62-
) -> None:
62+
) -> Literal[False]:
6363
if self.locked:
6464
self.release()
65+
return False
6566

6667
def __del__(self) -> None:
6768
if self.locked:

bpython/inspection.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@
2626
import pydoc
2727
import re
2828
from collections import namedtuple
29+
from typing import Any, Optional, Literal, Type
30+
from types import MemberDescriptorType, TracebackType
2931

3032
from pygments.token import Token
3133
from pygments.lexers import Python3Lexer
32-
from typing import Any
33-
from types import MemberDescriptorType
3434

3535
from .lazyre import LazyReCompile
3636

@@ -88,7 +88,12 @@ def __enter__(self):
8888
self.attribs = (__getattribute__, __getattr__)
8989
# /Dark magic
9090

91-
def __exit__(self, exc_type, exc_val, exc_tb):
91+
def __exit__(
92+
self,
93+
exc_type: Optional[Type[BaseException]],
94+
exc_val: Optional[BaseException],
95+
exc_tb: Optional[TracebackType],
96+
) -> Literal[False]:
9297
"""Restore an object's magic methods."""
9398
type_ = type(self.obj)
9499
__getattribute__, __getattr__ = self.attribs
@@ -98,6 +103,7 @@ def __exit__(self, exc_type, exc_val, exc_tb):
98103
if __getattr__ is not None:
99104
setattr(type_, "__getattr__", __getattr__)
100105
# /Dark magic
106+
return False
101107

102108

103109
class _Repr:

bpython/repl.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,11 @@
3636
from abc import abstractmethod
3737
from itertools import takewhile
3838
from pathlib import Path
39+
from types import ModuleType, TracebackType
40+
from typing import cast, Tuple, Any, Optional, Literal, Type
41+
3942
from pygments.lexers import Python3Lexer
4043
from pygments.token import Token
41-
from types import ModuleType
42-
from typing import cast, Tuple, Any
4344

4445
have_pyperclip = True
4546
try:
@@ -68,7 +69,12 @@ def __init__(self):
6869
def __enter__(self):
6970
self.start = self.time()
7071

71-
def __exit__(self, ty, val, tb):
72+
def __exit__(
73+
self,
74+
exc_type: Optional[Type[BaseException]],
75+
exc_val: Optional[BaseException],
76+
exc_tb: Optional[TracebackType],
77+
) -> Literal[False]:
7278
self.last_command = self.time() - self.start
7379
self.running_time += self.last_command
7480
return False

0 commit comments

Comments
 (0)