Skip to content

Commit b82061c

Browse files
committed
Try to fix #4811.
Ideally we should try to go upstream and make sure context is passed as an int always and not a str.
1 parent 9e067fb commit b82061c

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

IPython/core/debugger.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,12 @@ class Pdb(OldPdb):
228228
}
229229

230230
def __init__(
231-
self, completekey=None, stdin=None, stdout=None, context: int = 5, **kwargs
231+
self,
232+
completekey=None,
233+
stdin=None,
234+
stdout=None,
235+
context: int | None | str = 5,
236+
**kwargs,
232237
):
233238
"""Create a new IPython debugger.
234239
@@ -251,7 +256,11 @@ def __init__(
251256
The possibilities are python version dependent, see the python
252257
docs for more info.
253258
"""
254-
259+
# ipdb issue, see https://github.com/ipython/ipython/issues/14811
260+
if context is None:
261+
context = 5
262+
if isinstance(context, str):
263+
context = int(context)
255264
self.context = context
256265

257266
# `kwargs` ensures full compatibility with stdlib's `pdb.Pdb`.
@@ -298,7 +307,10 @@ def context(self) -> int:
298307
return self._context
299308

300309
@context.setter
301-
def context(self, value: int) -> None:
310+
def context(self, value: int | str) -> None:
311+
# ipdb issue see https://github.com/ipython/ipython/issues/14811
312+
if not isinstance(value, int):
313+
value = int(value)
302314
assert isinstance(value, int)
303315
assert value >= 0
304316
self._context = value

IPython/terminal/ptutils.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,14 +169,15 @@ def _get_completions(self, body, offset, cursor_position, ipyc):
169169
adjusted_text = _adjust_completion_text_based_on_context(
170170
c.text, body, offset
171171
)
172+
min_elide = 30 if self.shell is None else self.shell.min_elide
172173
if c.type == "function":
173174
yield Completion(
174175
adjusted_text,
175176
start_position=c.start - offset,
176177
display=_elide(
177178
display_text + "()",
178179
body[c.start : c.end],
179-
min_elide=self.shell.min_elide,
180+
min_elide=min_elide,
180181
),
181182
display_meta=c.type + c.signature,
182183
)
@@ -187,7 +188,7 @@ def _get_completions(self, body, offset, cursor_position, ipyc):
187188
display=_elide(
188189
display_text,
189190
body[c.start : c.end],
190-
min_elide=self.shell.min_elide,
191+
min_elide=min_elide,
191192
),
192193
display_meta=c.type,
193194
)

0 commit comments

Comments
 (0)