Skip to content

Commit

Permalink
Try to fix #4811.
Browse files Browse the repository at this point in the history
Ideally we should try to go upstream and make sure context is passed as
an int always and not a str.
  • Loading branch information
Carreau committed Mar 3, 2025
1 parent 9e067fb commit b82061c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
18 changes: 15 additions & 3 deletions IPython/core/debugger.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,12 @@ class Pdb(OldPdb):
}

def __init__(
self, completekey=None, stdin=None, stdout=None, context: int = 5, **kwargs
self,
completekey=None,
stdin=None,
stdout=None,
context: int | None | str = 5,
**kwargs,
):
"""Create a new IPython debugger.
Expand All @@ -251,7 +256,11 @@ def __init__(
The possibilities are python version dependent, see the python
docs for more info.
"""

# ipdb issue, see https://github.com/ipython/ipython/issues/14811
if context is None:
context = 5
if isinstance(context, str):
context = int(context)
self.context = context

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

@context.setter
def context(self, value: int) -> None:
def context(self, value: int | str) -> None:
# ipdb issue see https://github.com/ipython/ipython/issues/14811
if not isinstance(value, int):
value = int(value)
assert isinstance(value, int)
assert value >= 0
self._context = value
Expand Down
5 changes: 3 additions & 2 deletions IPython/terminal/ptutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,14 +169,15 @@ def _get_completions(self, body, offset, cursor_position, ipyc):
adjusted_text = _adjust_completion_text_based_on_context(
c.text, body, offset
)
min_elide = 30 if self.shell is None else self.shell.min_elide
if c.type == "function":
yield Completion(
adjusted_text,
start_position=c.start - offset,
display=_elide(
display_text + "()",
body[c.start : c.end],
min_elide=self.shell.min_elide,
min_elide=min_elide,
),
display_meta=c.type + c.signature,
)
Expand All @@ -187,7 +188,7 @@ def _get_completions(self, body, offset, cursor_position, ipyc):
display=_elide(
display_text,
body[c.start : c.end],
min_elide=self.shell.min_elide,
min_elide=min_elide,
),
display_meta=c.type,
)
Expand Down

0 comments on commit b82061c

Please sign in to comment.