diff --git a/python-repl-314/.pythonstartup b/python-repl-314/.pythonstartup new file mode 100644 index 0000000000..527ca13cdc --- /dev/null +++ b/python-repl-314/.pythonstartup @@ -0,0 +1,18 @@ +try: + from dataclasses import replace + + from _colorize import ANSIColors, default_theme, set_theme +except Exception: + # Running on an older Python or environment without _colorize + pass +else: + theme = default_theme.copy_with( + syntax=replace( + default_theme.syntax, + keyword=ANSIColors.BOLD_YELLOW, + string=ANSIColors.INTENSE_BLUE, + number=ANSIColors.RED, + comment=ANSIColors.GREY, + ), + ) + set_theme(theme) diff --git a/python-repl-314/README.md b/python-repl-314/README.md new file mode 100644 index 0000000000..615f83fb96 --- /dev/null +++ b/python-repl-314/README.md @@ -0,0 +1,3 @@ +# Python 3.14 Preview: REPL Autocompletion and Highlighting + +This folder provides the code examples for the Real Python tutorial [Python 3.14 Preview: REPL Autocompletion and Highlighting](https://realpython.com/python-repl-autocompletion-highlighting/). diff --git a/python-repl-314/syntax_highlighting_sample.py b/python-repl-314/syntax_highlighting_sample.py new file mode 100644 index 0000000000..fc536d936c --- /dev/null +++ b/python-repl-314/syntax_highlighting_sample.py @@ -0,0 +1,21 @@ +import pathlib + +BASE_DIR = pathlib.Path(".") +number = 42 +fruits = ["apple", "grape", "orange"] + + +def func(value): + """A sample docstring.""" + return f"The input value is: {value}" + + +def main(): + # A sample comment + func(number) + for fruit in fruits: + print(fruit) + + +if __name__ == "__main__": + main()