MCPcopy Index your code
hub / github.com/RustPython/RustPython / Theme

Class Theme

Lib/_colorize.py:211–255  ·  view source on GitHub ↗

A suite of themes for all sections of Python. When adding a new one, remember to also modify `copy_with` and `no_colors` below.

Source from the content-addressed store, hash-verified

209
210@dataclass(frozen=True)
211class Theme:
212 """A suite of themes for all sections of Python.
213
214 When adding a new one, remember to also modify `copy_with` and `no_colors`
215 below.
216 """
217 argparse: Argparse = field(default_factory=Argparse)
218 syntax: Syntax = field(default_factory=Syntax)
219 traceback: Traceback = field(default_factory=Traceback)
220 unittest: Unittest = field(default_factory=Unittest)
221
222 def copy_with(
223 self,
224 *,
225 argparse: Argparse | None = None,
226 syntax: Syntax | None = None,
227 traceback: Traceback | None = None,
228 unittest: Unittest | None = None,
229 ) -> Self:
230 """Return a new Theme based on this instance with some sections replaced.
231
232 Themes are immutable to protect against accidental modifications that
233 could lead to invalid terminal states.
234 """
235 return type(self)(
236 argparse=argparse or self.argparse,
237 syntax=syntax or self.syntax,
238 traceback=traceback or self.traceback,
239 unittest=unittest or self.unittest,
240 )
241
242 @classmethod
243 def no_colors(cls) -> Self:
244 """Return a new Theme where colors in all sections are empty strings.
245
246 This allows writing user code as if colors are always used. The color
247 fields will be ANSI color code strings when colorization is desired
248 and possible, and empty strings otherwise.
249 """
250 return cls(
251 argparse=Argparse.no_colors(),
252 syntax=Syntax.no_colors(),
253 traceback=Traceback.no_colors(),
254 unittest=Unittest.no_colors(),
255 )
256
257
258def get_colors(

Callers 1

_colorize.pyFile · 0.85

Calls 1

fieldFunction · 0.90

Tested by

no test coverage detected