From 2d3895cc9df6b6c1d462493984cff33942bdf7c5 Mon Sep 17 00:00:00 2001 From: Wasim Lorgat Date: Wed, 4 Oct 2023 15:17:41 +0000 Subject: [PATCH] Merged PR posit-dev/positron-python#223: fix pyright errors Merge pull request #223 from posit-dev/fix-pyright-errors fix pyright errors -------------------- Commit message for posit-dev/positron-python@b729ca28a1004e03d43dbbbe6879b87069dadd46: fix pyright errors Authored-by: Wasim Lorgat Signed-off-by: Wasim Lorgat --- .../positron-python/pythonFiles/positron/help.py | 11 ++++++----- .../positron-python/pythonFiles/positron/plots.py | 5 +++-- .../pythonFiles/positron_language_server.py | 1 + .../pythonFiles/tests/positron/test_plots.py | 8 +++++--- 4 files changed, 15 insertions(+), 10 deletions(-) diff --git a/extensions/positron-python/pythonFiles/positron/help.py b/extensions/positron-python/pythonFiles/positron/help.py index 1ee94ebe713..5fb9b243159 100644 --- a/extensions/positron-python/pythonFiles/positron/help.py +++ b/extensions/positron-python/pythonFiles/positron/help.py @@ -10,12 +10,11 @@ import pydoc from typing import TYPE_CHECKING, Any, Optional, Union -from ipykernel.ipkernel import IPythonKernel from pydantic import Field from .frontend import BaseFrontendEvent from .pydoc import start_server -from .utils import get_qualname, is_numpy_ufunc +from .utils import get_qualname if TYPE_CHECKING: from .frontend import FrontendService @@ -72,11 +71,13 @@ def help(topic="help"): >>> df = pandas.DataFrame() >>> help(df) """ - if IPythonKernel.initialized(): - kernel = IPythonKernel.instance() + from .positron_ipkernel import PositronIPyKernel + + if PositronIPyKernel.initialized(): + kernel = PositronIPyKernel.instance() kernel.help_service.show_help(topic) else: - raise Exception("Unexpected error. No IPythonKernel has been initialized.") + raise Exception("Unexpected error. No PositronIPyKernel has been initialized.") class HelpService: diff --git a/extensions/positron-python/pythonFiles/positron/plots.py b/extensions/positron-python/pythonFiles/positron/plots.py index a5c324f913d..83e5beec139 100644 --- a/extensions/positron-python/pythonFiles/positron/plots.py +++ b/extensions/positron-python/pythonFiles/positron/plots.py @@ -264,8 +264,9 @@ def _resize_pickled_figure( figure.set_size_inches(width_in, height_in) - format = InteractiveShell.instance().display_formatter.format - format_dict, md_dict = format(figure, include=formats, exclude=[]) # type: ignore + display_formatter = InteractiveShell.instance().display_formatter + assert display_formatter is not None, "Display formatter was not initialized" + format_dict, md_dict = display_formatter.format(figure, include=formats, exclude=[]) # type: ignore plt.close(figure) diff --git a/extensions/positron-python/pythonFiles/positron_language_server.py b/extensions/positron-python/pythonFiles/positron_language_server.py index ab9df6e24fe..1e477de0795 100644 --- a/extensions/positron-python/pythonFiles/positron_language_server.py +++ b/extensions/positron-python/pythonFiles/positron_language_server.py @@ -117,6 +117,7 @@ def parse_args() -> argparse.Namespace: # Initialize with empty argv, otherwise BaseIPythonApplication.initialize reuses our # command-line arguments in unexpected ways (e.g. logfile instructs it to log executed code). app.initialize(argv=[]) + assert app.kernel is not None, "Kernel was not initialized" app.kernel.start() logger.info(f"Process ID {os.getpid()}") diff --git a/extensions/positron-python/pythonFiles/tests/positron/test_plots.py b/extensions/positron-python/pythonFiles/tests/positron/test_plots.py index f81af0ad165..40e21fc3e0a 100644 --- a/extensions/positron-python/pythonFiles/tests/positron/test_plots.py +++ b/extensions/positron-python/pythonFiles/tests/positron/test_plots.py @@ -27,8 +27,10 @@ def setup_matplotlib() -> Iterable[None]: # Enable all IPython mimetype formatters ip = get_ipython() - active_types = ip.display_formatter.active_types - ip.display_formatter.active_types = ip.display_formatter.format_types + display_formatter = ip.display_formatter + assert display_formatter is not None, "Display formatter was not initialized" + active_types = display_formatter.active_types + display_formatter.active_types = display_formatter.format_types # type: ignore # Enable matplotlib IPython formatters configure_inline_support(ip, backend) @@ -36,7 +38,7 @@ def setup_matplotlib() -> Iterable[None]: yield # Restore the original active formatters - ip.display_formatter.active_types = active_types + display_formatter.active_types = active_types # type: ignore @pytest.fixture(scope="session")