Skip to content

Commit

Permalink
Prepare removal of unnecessary options of ColorSchemeTable. (#14307)
Browse files Browse the repository at this point in the history
  • Loading branch information
Carreau committed Jan 31, 2024
2 parents 93ffc15 + 3230aa3 commit a069d99
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions IPython/utils/coloransi.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@

__all__ = ["TermColors", "InputTermColors", "ColorScheme", "ColorSchemeTable"]

_sentinel = object()

color_templates = (
# Dark colors
("Black" , "0;30"),
Expand Down Expand Up @@ -159,18 +161,35 @@ def copy(self):
"""Return full copy of object"""
return ColorSchemeTable(self.values(),self.active_scheme_name)

def add_scheme(self,new_scheme):
def __setitem__(self, key: str, value: ColorScheme):
assert isinstance(key, str)
assert isinstance(value, ColorScheme)
super().__setitem__(key, value)

def add_scheme(self, new_scheme):
"""Add a new color scheme to the table."""
if not isinstance(new_scheme,ColorScheme):
if not isinstance(new_scheme, ColorScheme):
raise ValueError('ColorSchemeTable only accepts ColorScheme instances')
self[new_scheme.name] = new_scheme

def set_active_scheme(self,scheme,case_sensitive=0):
def set_active_scheme(self, scheme, case_sensitive=_sentinel):
"""Set the currently active scheme.
Names are by default compared in a case-insensitive way, but this can
be changed by setting the parameter case_sensitive to true."""

if case_sensitive is _sentinel:
case_sensitive = False
else:
warnings.warn(
"set_active_scheme(case_sensitive=...) is Pending "
"deprecation. Please comment on "
"https://github.com/ipython/ipython/issues/14306 "
"to let the ipython maintainer that you are affected.",
PendingDeprecationWarning,
stacklevel=2,
)

scheme_names = list(self.keys())
if case_sensitive:
valid_schemes = scheme_names
Expand Down

0 comments on commit a069d99

Please sign in to comment.