From ac490629e33f9032e23d4e6a024a0eefe18ad8d0 Mon Sep 17 00:00:00 2001 From: Taneli Hukkinen <3275109+hukkin@users.noreply.github.com> Date: Thu, 21 Oct 2021 13:25:09 +0300 Subject: [PATCH 1/3] Remove text file object support --- README.md | 1 - tests/test_misc.py | 9 --------- tomli/_parser.py | 12 +----------- 3 files changed, 1 insertion(+), 21 deletions(-) diff --git a/README.md b/README.md index c1faec4..3db4ffb 100644 --- a/README.md +++ b/README.md @@ -67,7 +67,6 @@ with open("path_to_file/conf.toml", "rb") as f: The file must be opened in binary mode (with the `"rb"` flag). Binary mode will enforce decoding the file as UTF-8 with universal newlines disabled, both of which are required to correctly parse TOML. -Support for text file objects is deprecated for removal in the next major release. ### Handle invalid TOML diff --git a/tests/test_misc.py b/tests/test_misc.py index 2eec882..032c8ff 100644 --- a/tests/test_misc.py +++ b/tests/test_misc.py @@ -3,8 +3,6 @@ from decimal import Decimal as D from pathlib import Path -import pytest - import tomli @@ -14,13 +12,6 @@ def test_load(tmp_path): file_path = tmp_path / "test.toml" file_path.write_text(content) - # Test text mode - with open(file_path, encoding="utf-8", newline="") as f: - with pytest.warns(DeprecationWarning): - actual = tomli.load(f) # type: ignore[arg-type] - assert actual == expected - - # Test binary mode with open(file_path, "rb") as bin_f: actual = tomli.load(bin_f) assert actual == expected diff --git a/tomli/_parser.py b/tomli/_parser.py index b712502..355d339 100644 --- a/tomli/_parser.py +++ b/tomli/_parser.py @@ -11,7 +11,6 @@ Optional, Tuple, ) -import warnings from tomli._re import ( RE_DATETIME, @@ -65,16 +64,7 @@ class TOMLDecodeError(ValueError): def load(fp: BinaryIO, *, parse_float: ParseFloat = float) -> Dict[str, Any]: """Parse TOML from a binary file object.""" s_bytes = fp.read() - try: - s = s_bytes.decode() - except AttributeError: - warnings.warn( - "Text file object support is deprecated in favor of binary file objects." - ' Use `open("foo.toml", "rb")` to open the file in binary mode.', - DeprecationWarning, - stacklevel=2, - ) - s = s_bytes # type: ignore[assignment] + s = s_bytes.decode() return loads(s, parse_float=parse_float) From 1e80b7182c88f10f2502672d4278c69ba4720dc2 Mon Sep 17 00:00:00 2001 From: Taneli Hukkinen <3275109+hukkin@users.noreply.github.com> Date: Mon, 25 Oct 2021 17:12:42 +0300 Subject: [PATCH 2/3] rm one line --- tomli/_parser.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tomli/_parser.py b/tomli/_parser.py index 15eba1b..d907239 100644 --- a/tomli/_parser.py +++ b/tomli/_parser.py @@ -49,8 +49,7 @@ class TOMLDecodeError(ValueError): def load(fp: BinaryIO, *, parse_float: ParseFloat = float) -> Dict[str, Any]: """Parse TOML from a binary file object.""" - s_bytes = fp.read() - s = s_bytes.decode() + s = fp.read().decode() return loads(s, parse_float=parse_float) From 583798914c95f933daead77d793663cda9393916 Mon Sep 17 00:00:00 2001 From: Taneli Hukkinen <3275109+hukkin@users.noreply.github.com> Date: Mon, 15 Nov 2021 12:54:11 +0200 Subject: [PATCH 3/3] Changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index ac3cc2f..583e52d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ - Removed - Python 3.6 support + - Support for text file objects as `load` input. Use binary file objects instead. ## 1.2.2