Skip to content

Commit 278f002

Browse files
authored
[python] adjust ipykernel raw_input docstring (#11069)
<!-- Thank you for submitting a pull request. If this is your first pull request you can find information about contributing here: * https://github.com/posit-dev/positron/blob/main/CONTRIBUTING.md We recommend synchronizing your branch with the latest changes in the main branch by either pulling or rebasing. --> <!-- Describe briefly what problem this pull request resolves, or what new feature it introduces. Include screenshots of any new or altered UI. Link to any GitHub issues but avoid "magic" keywords that will automatically close the issue. If there are any details about your approach that are unintuitive or you want to draw attention to, please describe them here. --> ### Release Notes <!-- Optionally, replace `N/A` with text to be included in the next release notes. The `N/A` bullets are ignored. If you refer to one or more Positron issues, these issues are used to collect information about the feature or bugfix, such as the relevant language pack as determined by Github labels of type `lang: `. The note will automatically be tagged with the language. These notes are typically filled by the Positron team. If you are an external contributor, you may ignore this section. --> #### New Features - N/A #### Bug Fixes - #9640 Help calls for Python's builtin `input()` function include explanation of `ipykernel.kernelbase.Kernel.raw_input` involvement. ### QA Notes in the console ```python help(input) ``` brings up info about why `raw_input` is being shown <img width="468" height="331" alt="Screenshot 2025-12-11 at 5 09 31 PM" src="https://github.com/user-attachments/assets/93b59b80-2a10-46f5-9bed-d29358b91884" />
1 parent 5c82baf commit 278f002

File tree

1 file changed

+19
-0
lines changed
  • extensions/positron-python/python_files/posit/positron

1 file changed

+19
-0
lines changed

extensions/positron-python/python_files/posit/positron/pydoc.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@
4242

4343
logger = logging.getLogger(__name__)
4444

45+
BUILTIN_FUNCTIONS = ["input"]
46+
4547

4648
def _compact_signature(obj: Any, name="", max_chars=45) -> str | None:
4749
"""
@@ -761,6 +763,11 @@ def _version_text(self, version: str) -> str:
761763
def _pydoc_getdoc(object_: Any) -> str:
762764
"""Get the doc string or comments for an object."""
763765
result = inspect.getdoc(object_) or inspect.getcomments(object_)
766+
try:
767+
if object_.__qualname__ == "Kernel.raw_input" and result is not None:
768+
result += _ipykernel_input_info()
769+
except AttributeError:
770+
pass
764771
return (result and re.sub("^ *\n", "", result.rstrip())) or ""
765772

766773

@@ -872,6 +879,8 @@ def _linkify_match(match: re.Match, object_: Any) -> str:
872879

873880
# Try to resolve `target` and replace it with a link.
874881
key = _resolve(name, object_)
882+
if name in BUILTIN_FUNCTIONS:
883+
key = name
875884
if key is None:
876885
logger.debug("Could not resolve")
877886
return match.group(0)
@@ -974,6 +983,16 @@ def _url_handler(url: str, content_type="text/html"):
974983
raise TypeError(f"unknown content type {content_type!r} for url {url}")
975984

976985

986+
def _ipykernel_input_info() -> str:
987+
"""Adjust docstring for ipykernel.kernelbase.Kernel.raw_input."""
988+
return """
989+
.. note::
990+
When running in an IPython kernel, calls to the builtin function `input` are intercepted
991+
and forwarded to the kernel's `raw_input` method, which communicates with
992+
the frontend to request user input.
993+
"""
994+
995+
977996
def start_server(port: int = 0):
978997
"""Adapted from pydoc.browser."""
979998
# Setting port to 0 will use an arbitrary port

0 commit comments

Comments
 (0)