From 32def19a2a9f8bf9333a9b41ecbdc23b98b9765a Mon Sep 17 00:00:00 2001 From: "Z.H" <29370032+onlyacat@users.noreply.github.com> Date: Thu, 22 Sep 2022 14:31:42 +0800 Subject: [PATCH 1/4] fix default ensure_ascii value to match docs. --- rich/__init__.py | 2 +- rich/console.py | 2 +- rich/json.py | 4 ++-- tests/test_console.py | 7 +++++++ 4 files changed, 11 insertions(+), 4 deletions(-) diff --git a/rich/__init__.py b/rich/__init__.py index 6658707fa..b631d5449 100644 --- a/rich/__init__.py +++ b/rich/__init__.py @@ -81,7 +81,7 @@ def print_json( indent: Union[None, int, str] = 2, highlight: bool = True, skip_keys: bool = False, - ensure_ascii: bool = True, + ensure_ascii: bool = False, check_circular: bool = True, allow_nan: bool = True, default: Optional[Callable[[Any], Any]] = None, diff --git a/rich/console.py b/rich/console.py index 8676e40b2..cce90becf 100644 --- a/rich/console.py +++ b/rich/console.py @@ -1722,7 +1722,7 @@ def print_json( indent: Union[None, int, str] = 2, highlight: bool = True, skip_keys: bool = False, - ensure_ascii: bool = True, + ensure_ascii: bool = False, check_circular: bool = True, allow_nan: bool = True, default: Optional[Callable[[Any], Any]] = None, diff --git a/rich/json.py b/rich/json.py index 1fc115a95..ed9ca1ea5 100644 --- a/rich/json.py +++ b/rich/json.py @@ -27,7 +27,7 @@ def __init__( indent: Union[None, int, str] = 2, highlight: bool = True, skip_keys: bool = False, - ensure_ascii: bool = True, + ensure_ascii: bool = False, check_circular: bool = True, allow_nan: bool = True, default: Optional[Callable[[Any], Any]] = None, @@ -56,7 +56,7 @@ def from_data( indent: Union[None, int, str] = 2, highlight: bool = True, skip_keys: bool = False, - ensure_ascii: bool = True, + ensure_ascii: bool = False, check_circular: bool = True, allow_nan: bool = True, default: Optional[Callable[[Any], Any]] = None, diff --git a/tests/test_console.py b/tests/test_console.py index 369f0a67e..c67217e84 100644 --- a/tests/test_console.py +++ b/tests/test_console.py @@ -239,6 +239,13 @@ def test_print_json_ensure_ascii(): expected = '\x1b[1m{\x1b[0m\n \x1b[1;34m"foo"\x1b[0m: \x1b[32m"💩"\x1b[0m\n\x1b[1m}\x1b[0m\n' assert result == expected +def test_print_json_with_default_ensure_ascii(): + console = Console(file=io.StringIO(), color_system="truecolor") + console.print_json(data={"foo": "💩"}) + result = console.file.getvalue() + print(repr(result)) + expected = '\x1b[1m{\x1b[0m\n \x1b[1;34m"foo"\x1b[0m: \x1b[32m"💩"\x1b[0m\n\x1b[1m}\x1b[0m\n' + assert result == expected def test_print_json_indent_none(): console = Console(file=io.StringIO(), color_system="truecolor") From 86ebeec77564eacdacf60fb59970d670b30ddbb4 Mon Sep 17 00:00:00 2001 From: "Z.H" <29370032+onlyacat@users.noreply.github.com> Date: Thu, 22 Sep 2022 14:45:18 +0800 Subject: [PATCH 2/4] Update CHANGELOG and CONTRIBUTORS --- CHANGELOG.md | 1 + CONTRIBUTORS.md | 1 + 2 files changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index d6eebd4fd..b88e033e9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Fix NO_COLOR support on legacy Windows https://github.com/Textualize/rich/pull/2458 - Fix pretty printer handling of cyclic references https://github.com/Textualize/rich/pull/2524 - Fix missing `mode` property on file wrapper breaking uploads via `requests` https://github.com/Textualize/rich/pull/2495 +- Fix mismatching default value of prarmeter `ensure_ascii` https://github.com/Textualize/rich/pull/2538 ### Changed diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index 1972229ab..155fb61bc 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -55,3 +55,4 @@ The following people have contributed to the development of Rich: - [Motahhar Mokfi](https://github.com/motahhar) - [Tomer Shalev](https://github.com/tomers) - [Serkan UYSAL](https://github.com/uysalserkan) +- [Zhe Huang](https://github.com/onlyacat) \ No newline at end of file From 68cd446183e653f0365f7ff5c7dc0a15c946e256 Mon Sep 17 00:00:00 2001 From: "Z.H" <29370032+onlyacat@users.noreply.github.com> Date: Thu, 22 Sep 2022 14:48:37 +0800 Subject: [PATCH 3/4] format the style. --- tests/test_console.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/test_console.py b/tests/test_console.py index c67217e84..4509f6b2d 100644 --- a/tests/test_console.py +++ b/tests/test_console.py @@ -239,6 +239,7 @@ def test_print_json_ensure_ascii(): expected = '\x1b[1m{\x1b[0m\n \x1b[1;34m"foo"\x1b[0m: \x1b[32m"💩"\x1b[0m\n\x1b[1m}\x1b[0m\n' assert result == expected + def test_print_json_with_default_ensure_ascii(): console = Console(file=io.StringIO(), color_system="truecolor") console.print_json(data={"foo": "💩"}) @@ -247,6 +248,7 @@ def test_print_json_with_default_ensure_ascii(): expected = '\x1b[1m{\x1b[0m\n \x1b[1;34m"foo"\x1b[0m: \x1b[32m"💩"\x1b[0m\n\x1b[1m}\x1b[0m\n' assert result == expected + def test_print_json_indent_none(): console = Console(file=io.StringIO(), color_system="truecolor") data = {"name": "apple", "count": 1} From c49e5a731fdacaa4036afa1fe4c967f733ca224b Mon Sep 17 00:00:00 2001 From: Will McGugan Date: Fri, 23 Sep 2022 13:41:31 +0100 Subject: [PATCH 4/4] typo fix --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b88e033e9..2ed549a6e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,7 +21,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Fix NO_COLOR support on legacy Windows https://github.com/Textualize/rich/pull/2458 - Fix pretty printer handling of cyclic references https://github.com/Textualize/rich/pull/2524 - Fix missing `mode` property on file wrapper breaking uploads via `requests` https://github.com/Textualize/rich/pull/2495 -- Fix mismatching default value of prarmeter `ensure_ascii` https://github.com/Textualize/rich/pull/2538 +- Fix mismatching default value of parameter `ensure_ascii` https://github.com/Textualize/rich/pull/2538 ### Changed