Skip to content

Commit

Permalink
Deprecate text file objects as input to load (#106)
Browse files Browse the repository at this point in the history
  • Loading branch information
hukkin authored Jul 29, 2021
1 parent b94a0d2 commit 0335770
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 8 deletions.
11 changes: 5 additions & 6 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ name: Tests
on:
push:
branches: [ master ]
tags:
- '[0-9]+.[0-9]+.[0-9]+*'
tags: [ '[0-9]+.[0-9]+.[0-9]+*' ]
pull_request:
branches: [ master ]

Expand All @@ -17,7 +16,7 @@ jobs:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
with:
python-version: 3.8
python-version: '3.8'

- name: Install pre-commit
run: |
Expand All @@ -33,7 +32,7 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
python-version: [pypy-3.6, 3.6, 3.7, pypy-3.7, 3.8, 3.9, 3.10-dev]
python-version: ['pypy-3.6', 'pypy-3.7', '3.6', '3.7', '3.8', '3.9', '3.10-dev']
os: [ubuntu-latest, macos-latest, windows-latest]
continue-on-error: ${{ matrix.python-version == '3.10-dev' }}

Expand Down Expand Up @@ -69,7 +68,7 @@ jobs:

- uses: actions/setup-python@v2
with:
python-version: 3.7
python-version: '3.7'

- name: Install (deps and package)
run: |
Expand Down Expand Up @@ -97,7 +96,7 @@ jobs:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
with:
python-version: 3.7
python-version: '3.7'
- name: Install Flit
run: |
pip install "flit==3.2.0"
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## 1.2.0

- Deprecated
- Text file objects as input to `load`.
Binary file objects should be used instead to avoid opening a TOML file with universal newlines or with an encoding other than UTF-8.

## 1.1.0

- Added
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ with open("path_to_file/conf.toml", "rb") as f:
Opening the file in binary mode (with the `"rb"` flag) is highly encouraged.
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 may be deprecated for removal in a future release.
Support for text file objects is deprecated for removal in the next major release.

### Handle invalid TOML<a name="handle-invalid-toml"></a>

Expand Down
2 changes: 1 addition & 1 deletion fuzzer/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# sudo apt-get install clang
wheel
atheris==2.0.0
atheris==2.0.3
tomli_w>=0.2.2
7 changes: 7 additions & 0 deletions tomli/_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
Optional,
Tuple,
)
import warnings

from tomli._re import (
RE_DATETIME,
Expand Down Expand Up @@ -66,6 +67,12 @@ def load(fp: IO, *, parse_float: ParseFloat = float) -> Dict[str, Any]:
s = fp.read()
if isinstance(s, bytes):
s = s.decode()
else:
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,
)
return loads(s, parse_float=parse_float)


Expand Down

0 comments on commit 0335770

Please sign in to comment.