Skip to content

Commit

Permalink
Set sys.ps1 to let some programs know they are run in a REPL
Browse files Browse the repository at this point in the history
  • Loading branch information
Freed-Wu committed Jul 29, 2024
1 parent 5021832 commit c649e6b
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions ptpython/prompt_style.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import annotations

import sys
from abc import ABCMeta, abstractmethod
from typing import TYPE_CHECKING

Expand All @@ -14,7 +15,12 @@
class PromptStyle(metaclass=ABCMeta):
"""
Base class for all prompts.
It will set `sys.ps1` to let some programs know they are run in a REPL.
See: https://github.com/TylerYep/torchinfo/issues/216
"""
def __init__(self) -> None:
sys.ps1 = getattr(sys, "ps1", ">>> ")

@abstractmethod
def in_prompt(self) -> AnyFormattedText:
Expand Down Expand Up @@ -43,6 +49,7 @@ class IPythonPrompt(PromptStyle):
"""

def __init__(self, python_input: PythonInput) -> None:
super().__init__()
self.python_input = python_input

def in_prompt(self) -> AnyFormattedText:
Expand Down

0 comments on commit c649e6b

Please sign in to comment.