diff --git a/extensions/positron-python/pythonFiles/positron/inspectors.py b/extensions/positron-python/pythonFiles/positron/inspectors.py index a91c1db0c8e..2c542d6b7e2 100644 --- a/extensions/positron-python/pythonFiles/positron/inspectors.py +++ b/extensions/positron-python/pythonFiles/positron/inspectors.py @@ -13,15 +13,9 @@ import types import uuid from abc import ABC, abstractmethod -from collections.abc import ( - Mapping, - MutableMapping, - MutableSequence, - MutableSet, - Sequence, - Set, -) +from collections.abc import Mapping, MutableMapping, MutableSequence, MutableSet, Sequence, Set from typing import ( + TYPE_CHECKING, Any, Callable, Collection, @@ -35,7 +29,6 @@ Protocol, Sized, Tuple, - TYPE_CHECKING, Type, TypeVar, Union, @@ -567,7 +560,7 @@ def copy(self, value: torch.Tensor) -> torch.Tensor: class _BaseMapInspector(PositronInspector[MT], ABC): - def get_kind(self, value: Mapping) -> str: + def get_kind(self, value: MT) -> str: return "map" @abstractmethod diff --git a/extensions/positron-python/pythonFiles/positron/positron_ipkernel.py b/extensions/positron-python/pythonFiles/positron/positron_ipkernel.py index cba006c025b..6efbcf66fc7 100644 --- a/extensions/positron-python/pythonFiles/positron/positron_ipkernel.py +++ b/extensions/positron-python/pythonFiles/positron/positron_ipkernel.py @@ -4,32 +4,32 @@ """ Positron extensions to the iPython Kernel.""" from __future__ import annotations + import asyncio import logging import warnings from collections.abc import Iterable from itertools import chain -from typing import Any, Callable, Container, Dict, Mapping, Optional, Set, Tuple, Type +from typing import Any, Callable, Container, Coroutine, Dict, Mapping, Optional, Set, Tuple, Type +import traitlets from ipykernel.comm.manager import CommManager from ipykernel.ipkernel import IPythonKernel from ipykernel.kernelapp import IPKernelApp -from ipykernel.zmqshell import ZMQInteractiveShell, ZMQDisplayPublisher -from IPython.core import oinspect +from ipykernel.zmqshell import ZMQDisplayPublisher, ZMQInteractiveShell +from IPython.core import oinspect, page from IPython.core.interactiveshell import InteractiveShell -from IPython.core.magic import Magics, line_magic, magics_class, needs_local_scope, MagicsManager -from IPython.core import page +from IPython.core.magic import Magics, MagicsManager, line_magic, magics_class, needs_local_scope from IPython.utils import PyColorize -import traitlets from .dataviewer import DataViewerService -from .variables import VariablesService from .frontend import FrontendService from .help import HelpService from .inspectors import get_inspector from .lsp import LSPService from .plots import PositronDisplayPublisherHook from .utils import cancel_tasks, create_task +from .variables import VariablesService POSITRON_DATA_VIEWER_COMM = "positron.dataViewer" """The comm channel target_name for Positron's Data Viewer""" @@ -69,12 +69,11 @@ class PositronIPythonInspector(oinspect.Inspector): def pinfo( self, obj: Any, - oname: str, - formatter: Callable[[str], Dict[str, str]], - info: oinspect.OInfo, - *, - detail_level: int, - enable_html_pager: bool, + oname: str = "", + formatter: Optional[Callable[[str], Dict[str, str]]] = None, + info: Optional[oinspect.OInfo] = None, + detail_level: int = 0, + enable_html_pager: bool = True, omit_sections: Container[str] = (), ) -> None: # Intercept `%pinfo obj` / `obj?` calls, and instead use Positron's help service @@ -106,7 +105,7 @@ class PositronShell(ZMQInteractiveShell): ).tag(config=True) @traitlets.observe("colors") - def init_inspector(self, change: Optional[traitlets.Bunch] = None) -> None: + def init_inspector(self, changes: Optional[traitlets.Bunch] = None) -> None: # Override to pass `parent=self` to the inspector self.inspector = self.inspector_class( oinspect.InspectColors, @@ -160,7 +159,6 @@ class PositronIPyKernel(IPythonKernel): shell: PositronShell comm_manager: CommManager - execution_count: int shell_class: PositronShell = traitlets.Type(PositronShell, klass=InteractiveShell) # type: ignore @@ -230,7 +228,7 @@ def start(self) -> None: super().start() self.help_service.start() - async def do_shutdown(self, restart: bool) -> Dict[str, Any]: + async def do_shutdown(self, restart: bool) -> Dict[str, str | bool]: # type: ignore ReportIncompatibleMethodOverride """ Handle kernel shutdown. """ diff --git a/extensions/positron-python/pythonFiles/positron/positron_jedilsp.py b/extensions/positron-python/pythonFiles/positron/positron_jedilsp.py index d2db1f6ab72..2b8949062aa 100644 --- a/extensions/positron-python/pythonFiles/positron/positron_jedilsp.py +++ b/extensions/positron-python/pythonFiles/positron/positron_jedilsp.py @@ -122,7 +122,7 @@ class HelpTopicRequest: class PositronJediLanguageServerProtocol(JediLanguageServerProtocol): - def get_message_type(self, method: str) -> Optional[Type]: + def get_message_type(self, method: str) -> Optional[Type]: # type: ignore # Overriden to include custom Positron LSP messages. # Doing so ensures that the corresponding feature function receives `params` of the correct type. if method == _HELP_TOPIC: @@ -137,7 +137,7 @@ def __init__(self, *args: Any, **kwargs: Any) -> None: super().__init__(*args, **kwargs) self.loop: asyncio.AbstractEventLoop - self.lsp: PositronJediLanguageServerProtocol + self.lsp: PositronJediLanguageServerProtocol # type: ignore reportIncompatibleVariableOverride # LSP comm used to notify the frontend when the server is ready self._comm: Optional[BaseComm] = None @@ -363,7 +363,7 @@ def positron_completion( has_whitespace = " " in trimmed_line if server.kernel is not None and not (is_completing_attribute or has_whitespace): # Cast type from traitlets.Dict to typing.Dict - magic_commands = cast(Dict[str, Callable], server.kernel.shell.magics_manager.lsmagic()) + magic_commands = cast(Dict[str, Any], server.kernel.shell.magics_manager.lsmagic()) chars_before_cursor = trimmed_line[: params.position.character] diff --git a/extensions/positron-python/pythonFiles/positron/pydoc.py b/extensions/positron-python/pythonFiles/positron/pydoc.py index c1bbec6b2c6..92638f9787e 100644 --- a/extensions/positron-python/pythonFiles/positron/pydoc.py +++ b/extensions/positron-python/pythonFiles/positron/pydoc.py @@ -218,7 +218,7 @@ def page(self, title, contents): ) # --- End Positron --- - def heading(self, title: str, extras="") -> str: + def heading(self, title: str, extras="") -> str: # type: ignore ReportIncompatibleMethodOverride """Format a page heading.""" # Simplified version of pydoc.HTMLDoc.heading that doesn't use tables lines = [f"