A suite of themes for all sections of Python. When adding a new one, remember to also modify `copy_with` and `no_colors` below.
| 370 | |
| 371 | @dataclass(frozen=True, kw_only=True) |
| 372 | class Theme: |
| 373 | """A suite of themes for all sections of Python. |
| 374 | |
| 375 | When adding a new one, remember to also modify `copy_with` and `no_colors` |
| 376 | below. |
| 377 | """ |
| 378 | argparse: Argparse = field(default_factory=Argparse) |
| 379 | difflib: Difflib = field(default_factory=Difflib) |
| 380 | fancycompleter: FancyCompleter = field(default_factory=FancyCompleter) |
| 381 | live_profiler: LiveProfiler = field(default_factory=LiveProfiler) |
| 382 | syntax: Syntax = field(default_factory=Syntax) |
| 383 | traceback: Traceback = field(default_factory=Traceback) |
| 384 | unittest: Unittest = field(default_factory=Unittest) |
| 385 | |
| 386 | def copy_with( |
| 387 | self, |
| 388 | *, |
| 389 | argparse: Argparse | None = None, |
| 390 | difflib: Difflib | None = None, |
| 391 | fancycompleter: FancyCompleter | None = None, |
| 392 | live_profiler: LiveProfiler | None = None, |
| 393 | syntax: Syntax | None = None, |
| 394 | traceback: Traceback | None = None, |
| 395 | unittest: Unittest | None = None, |
| 396 | ) -> Self: |
| 397 | """Return a new Theme based on this instance with some sections replaced. |
| 398 | |
| 399 | Themes are immutable to protect against accidental modifications that |
| 400 | could lead to invalid terminal states. |
| 401 | """ |
| 402 | return type(self)( |
| 403 | argparse=argparse or self.argparse, |
| 404 | difflib=difflib or self.difflib, |
| 405 | fancycompleter=fancycompleter or self.fancycompleter, |
| 406 | live_profiler=live_profiler or self.live_profiler, |
| 407 | syntax=syntax or self.syntax, |
| 408 | traceback=traceback or self.traceback, |
| 409 | unittest=unittest or self.unittest, |
| 410 | ) |
| 411 | |
| 412 | @classmethod |
| 413 | def no_colors(cls) -> Self: |
| 414 | """Return a new Theme where colors in all sections are empty strings. |
| 415 | |
| 416 | This allows writing user code as if colors are always used. The color |
| 417 | fields will be ANSI color code strings when colorization is desired |
| 418 | and possible, and empty strings otherwise. |
| 419 | """ |
| 420 | return cls( |
| 421 | argparse=Argparse.no_colors(), |
| 422 | difflib=Difflib.no_colors(), |
| 423 | fancycompleter=FancyCompleter.no_colors(), |
| 424 | live_profiler=LiveProfiler.no_colors(), |
| 425 | syntax=Syntax.no_colors(), |
| 426 | traceback=Traceback.no_colors(), |
| 427 | unittest=Unittest.no_colors(), |
| 428 | ) |
| 429 |
no test coverage detected
searching dependent graphs…