Skip to content

Commit

Permalink
Merged PR posit-dev/positron-python#223: fix pyright errors
Browse files Browse the repository at this point in the history
Merge pull request #223 from posit-dev/fix-pyright-errors

fix pyright errors
--------------------
Commit message for posit-dev/positron-python@b729ca2:

fix pyright errors


Authored-by: Wasim Lorgat <mwlorgat@gmail.com>
Signed-off-by: Wasim Lorgat <mwlorgat@gmail.com>
  • Loading branch information
seeM authored and wesm committed Mar 28, 2024
1 parent 443460f commit 2d3895c
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 10 deletions.
11 changes: 6 additions & 5 deletions extensions/positron-python/pythonFiles/positron/help.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down
5 changes: 3 additions & 2 deletions extensions/positron-python/pythonFiles/positron/plots.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,18 @@ 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)

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")
Expand Down

0 comments on commit 2d3895c

Please sign in to comment.