From a103b0798e55c7d06c57c176895422e9cf403050 Mon Sep 17 00:00:00 2001 From: Taneli Hukkinen <3275109+hukkin@users.noreply.github.com> Date: Sun, 1 Aug 2021 11:26:54 +0300 Subject: [PATCH] Remove use of `isinstance` --- README.md | 2 +- tomli/_parser.py | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 89efb84..c1faec4 100644 --- a/README.md +++ b/README.md @@ -64,7 +64,7 @@ with open("path_to_file/conf.toml", "rb") as f: toml_dict = tomli.load(f) ``` -Opening the file in binary mode (with the `"rb"` flag) is highly encouraged. +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. diff --git a/tomli/_parser.py b/tomli/_parser.py index afc2121..7852eb8 100644 --- a/tomli/_parser.py +++ b/tomli/_parser.py @@ -63,11 +63,11 @@ class TOMLDecodeError(ValueError): def load(fp: IO, *, parse_float: ParseFloat = float) -> Dict[str, Any]: - """Parse TOML from a file object.""" + """Parse TOML from a binary file object.""" s = fp.read() - if isinstance(s, bytes): + try: s = s.decode() - else: + 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.',