From 96dfe2cef79eb4c2a441d5b1b36c3ef357372c9f Mon Sep 17 00:00:00 2001 From: Michael Wayne Goodman Date: Fri, 22 Oct 2021 16:10:08 -0700 Subject: [PATCH 1/5] Make TOMLDecodeError show 'tomli' as its module (#135) * Make TOMLDecodeError show 'tomli' as its module * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Move __module__ assignment to __init__, add test * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- tests/test_error.py | 4 ++++ tomli/__init__.py | 3 +++ 2 files changed, 7 insertions(+) diff --git a/tests/test_error.py b/tests/test_error.py index 44f7797..d2d982c 100644 --- a/tests/test_error.py +++ b/tests/test_error.py @@ -31,3 +31,7 @@ def test_invalid_char_quotes(): with pytest.raises(tomli.TOMLDecodeError) as exc_info: tomli.loads("v = '\n'") assert " '\\n' " in str(exc_info.value) + + +def test_module_name(): + assert tomli.TOMLDecodeError().__module__ == "tomli" diff --git a/tomli/__init__.py b/tomli/__init__.py index d99eadc..7061912 100644 --- a/tomli/__init__.py +++ b/tomli/__init__.py @@ -4,3 +4,6 @@ __version__ = "1.2.1" # DO NOT EDIT THIS LINE MANUALLY. LET bump2version UTILITY DO IT from tomli._parser import TOMLDecodeError, load, loads + +# Pretend this exception was created here. +TOMLDecodeError.__module__ = "tomli" From 744634e9f4a76b284db578a2c5231086d57f5402 Mon Sep 17 00:00:00 2001 From: Taneli Hukkinen <3275109+hukkin@users.noreply.github.com> Date: Sat, 23 Oct 2021 21:15:51 +0300 Subject: [PATCH 2/5] Update codecov GitHub action Committed via https://github.com/asottile/all-repos --- .github/workflows/tests.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index e615d74..0c246e3 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -55,7 +55,7 @@ jobs: - name: Report coverage if: matrix.os == 'ubuntu-latest' && matrix.python-version == '3.6' - uses: codecov/codecov-action@v1 + uses: codecov/codecov-action@v2 test-built-package: runs-on: ubuntu-latest From 2179f2a0844c0536fb9f69b67a938ae982b7e4da Mon Sep 17 00:00:00 2001 From: layday Date: Mon, 25 Oct 2021 02:38:09 +0300 Subject: [PATCH 3/5] Eliminate import cycle in `_re.py` At the expense of one additional import. This is to be able to resolve types from `TYPE_CHECKING` blocks at runtime with `sphinx-autodoc-typehints` [1] which might otherwise involve expensive imports or optional dependencies and where scoping the tomli import is impracticable. [1] https://github.com/agronholm/sphinx-autodoc-typehints --- tomli/_parser.py | 18 ++---------------- tomli/_re.py | 5 ++--- tomli/_types.py | 6 ++++++ 3 files changed, 10 insertions(+), 19 deletions(-) create mode 100644 tomli/_types.py diff --git a/tomli/_parser.py b/tomli/_parser.py index b712502..89e81c3 100644 --- a/tomli/_parser.py +++ b/tomli/_parser.py @@ -1,16 +1,6 @@ import string from types import MappingProxyType -from typing import ( - Any, - BinaryIO, - Callable, - Dict, - FrozenSet, - Iterable, - NamedTuple, - Optional, - Tuple, -) +from typing import Any, BinaryIO, Dict, FrozenSet, Iterable, NamedTuple, Optional, Tuple import warnings from tomli._re import ( @@ -21,6 +11,7 @@ match_to_localtime, match_to_number, ) +from tomli._types import Key, ParseFloat, Pos ASCII_CTRL = frozenset(chr(i) for i in range(32)) | frozenset(chr(127)) @@ -52,11 +43,6 @@ } ) -# Type annotations -ParseFloat = Callable[[str], Any] -Key = Tuple[str, ...] -Pos = int - class TOMLDecodeError(ValueError): """An error raised if a document is not valid TOML.""" diff --git a/tomli/_re.py b/tomli/_re.py index d1bef1a..9126829 100644 --- a/tomli/_re.py +++ b/tomli/_re.py @@ -1,10 +1,9 @@ from datetime import date, datetime, time, timedelta, timezone, tzinfo from functools import lru_cache import re -from typing import TYPE_CHECKING, Any, Optional, Union +from typing import Any, Optional, Union -if TYPE_CHECKING: - from tomli._parser import ParseFloat +from tomli._types import ParseFloat # E.g. # - 00:32:00.999999 diff --git a/tomli/_types.py b/tomli/_types.py new file mode 100644 index 0000000..e37cc80 --- /dev/null +++ b/tomli/_types.py @@ -0,0 +1,6 @@ +from typing import Any, Callable, Tuple + +# Type annotations +ParseFloat = Callable[[str], Any] +Key = Tuple[str, ...] +Pos = int From 7ec5b01fb66b86ab7a52d48cc278698c1111eb9b Mon Sep 17 00:00:00 2001 From: Taneli Hukkinen <3275109+hukkin@users.noreply.github.com> Date: Mon, 25 Oct 2021 12:46:00 +0300 Subject: [PATCH 4/5] Finalize 1.2.2 changelog --- CHANGELOG.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e581cc3..7b0720d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,8 +2,16 @@ ## **unreleased** +- no changes yet + +## 1.2.2 + - Fixed - Illegal characters in error messages were surrounded by two pairs of quotation marks +- Improved + - `TOMLDecodeError.__module__` is now the public import path (`tomli`) instead of private import path (`tomli._parser`) + - Eliminated an import cycle when `typing.TYPE_CHECKING` is `True`. + This allows `sphinx-autodoc-typehints` to resolve type annotations. ## 1.2.1 From 16a2e08d630b4d834e211d801e1581288765e7d5 Mon Sep 17 00:00:00 2001 From: Taneli Hukkinen <3275109+hukkin@users.noreply.github.com> Date: Mon, 25 Oct 2021 12:46:45 +0300 Subject: [PATCH 5/5] =?UTF-8?q?Bump=20version:=201.2.1=20=E2=86=92=201.2.2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .bumpversion.cfg | 2 +- pyproject.toml | 2 +- tomli/__init__.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.bumpversion.cfg b/.bumpversion.cfg index 2df26c8..94a23ef 100644 --- a/.bumpversion.cfg +++ b/.bumpversion.cfg @@ -2,7 +2,7 @@ commit = True tag = True tag_name = {new_version} -current_version = 1.2.1 +current_version = 1.2.2 [bumpversion:file:pyproject.toml] search = version = "{current_version}" # DO NOT EDIT THIS LINE MANUALLY. LET bump2version UTILITY DO IT diff --git a/pyproject.toml b/pyproject.toml index a26ff62..c562ff3 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "flit_core.buildapi" [project] name = "tomli" -version = "1.2.1" # DO NOT EDIT THIS LINE MANUALLY. LET bump2version UTILITY DO IT +version = "1.2.2" # DO NOT EDIT THIS LINE MANUALLY. LET bump2version UTILITY DO IT description = "A lil' TOML parser" authors = [ { name = "Taneli Hukkinen", email = "hukkin@users.noreply.github.com" }, diff --git a/tomli/__init__.py b/tomli/__init__.py index 7061912..7bcdbab 100644 --- a/tomli/__init__.py +++ b/tomli/__init__.py @@ -1,7 +1,7 @@ """A lil' TOML parser.""" __all__ = ("loads", "load", "TOMLDecodeError") -__version__ = "1.2.1" # DO NOT EDIT THIS LINE MANUALLY. LET bump2version UTILITY DO IT +__version__ = "1.2.2" # DO NOT EDIT THIS LINE MANUALLY. LET bump2version UTILITY DO IT from tomli._parser import TOMLDecodeError, load, loads