diff options
-rw-r--r-- | .pre-commit-config.yaml | 8 | ||||
-rw-r--r-- | CHANGES.rst | 9 | ||||
-rw-r--r-- | requirements/dev.txt | 27 | ||||
-rw-r--r-- | requirements/docs.txt | 12 | ||||
-rw-r--r-- | requirements/typing.txt | 6 | ||||
-rw-r--r-- | src/markupsafe/__init__.py | 9 | ||||
-rw-r--r-- | tests/test_markupsafe.py | 6 |
7 files changed, 49 insertions, 28 deletions
diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 0b529a1..3cc2aa3 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -2,17 +2,17 @@ ci: autoupdate_schedule: monthly repos: - repo: https://github.com/asottile/pyupgrade - rev: v2.15.0 + rev: v2.23.1 hooks: - id: pyupgrade args: ["--py36-plus"] - repo: https://github.com/asottile/reorder_python_imports - rev: v2.5.0 + rev: v2.6.0 hooks: - id: reorder-python-imports args: ["--application-directories", "src"] - repo: https://github.com/psf/black - rev: 21.5b1 + rev: 21.7b0 hooks: - id: black - repo: https://github.com/PyCQA/flake8 @@ -21,7 +21,7 @@ repos: - id: flake8 additional_dependencies: [flake8-bugbear] - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v3.4.0 + rev: v4.0.1 hooks: - id: fix-byte-order-marker - id: trailing-whitespace diff --git a/CHANGES.rst b/CHANGES.rst index e8cc448..3f98624 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -1,3 +1,12 @@ +Version 2.1.0 +------------- + +Unreleased + +- Raise error on missing single placeholder during string + interpolation. :issue:`225` + + Version 2.0.2 ------------- diff --git a/requirements/dev.txt b/requirements/dev.txt index 3c10cfb..be86ee7 100644 --- a/requirements/dev.txt +++ b/requirements/dev.txt @@ -40,10 +40,10 @@ jinja2==3.0.1 # via sphinx markupsafe==2.0.1 # via jinja2 +mypy==0.910 + # via -r requirements/typing.in mypy-extensions==0.4.3 # via mypy -mypy==0.812 - # via -r requirements/typing.in nodeenv==1.6.0 # via pre-commit packaging==20.9 @@ -56,13 +56,13 @@ pallets-sphinx-themes==2.0.1 # via -r requirements/docs.in pep517==0.10.0 # via pip-tools -pip-tools==6.1.0 +pip-tools==6.2.0 # via -r requirements/dev.in pluggy==0.13.1 # via # pytest # tox -pre-commit==2.12.1 +pre-commit==2.13.0 # via -r requirements/dev.in py==1.10.0 # via @@ -86,19 +86,19 @@ six==1.16.0 # virtualenv snowballstemmer==2.1.0 # via sphinx -sphinx-issues==1.2.0 - # via -r requirements/docs.in -sphinx==4.0.2 +sphinx==4.1.2 # via # -r requirements/docs.in # pallets-sphinx-themes # sphinx-issues # sphinxcontrib-log-cabinet +sphinx-issues==1.2.0 + # via -r requirements/docs.in sphinxcontrib-applehelp==1.0.2 # via sphinx sphinxcontrib-devhelp==1.0.2 # via sphinx -sphinxcontrib-htmlhelp==1.0.3 +sphinxcontrib-htmlhelp==2.0.0 # via sphinx sphinxcontrib-jsmath==1.0.1 # via sphinx @@ -106,26 +106,27 @@ sphinxcontrib-log-cabinet==1.0.1 # via -r requirements/docs.in sphinxcontrib-qthelp==1.0.3 # via sphinx -sphinxcontrib-serializinghtml==1.1.4 +sphinxcontrib-serializinghtml==1.1.5 # via sphinx toml==0.10.2 # via + # mypy # pep517 # pre-commit # pytest # tox -tox==3.23.1 +tox==3.24.1 # via -r requirements/dev.in -typed-ast==1.4.3 - # via mypy typing-extensions==3.10.0.0 # via mypy -urllib3==1.26.4 +urllib3==1.26.5 # via requests virtualenv==20.4.6 # via # pre-commit # tox +wheel==0.36.2 + # via pip-tools # The following packages are considered to be unsafe in a requirements file: # pip diff --git a/requirements/docs.txt b/requirements/docs.txt index 93878a7..885e6ff 100644 --- a/requirements/docs.txt +++ b/requirements/docs.txt @@ -38,19 +38,19 @@ requests==2.25.1 # via sphinx snowballstemmer==2.1.0 # via sphinx -sphinx-issues==1.2.0 - # via -r requirements/docs.in -sphinx==4.0.2 +sphinx==4.1.2 # via # -r requirements/docs.in # pallets-sphinx-themes # sphinx-issues # sphinxcontrib-log-cabinet +sphinx-issues==1.2.0 + # via -r requirements/docs.in sphinxcontrib-applehelp==1.0.2 # via sphinx sphinxcontrib-devhelp==1.0.2 # via sphinx -sphinxcontrib-htmlhelp==1.0.3 +sphinxcontrib-htmlhelp==2.0.0 # via sphinx sphinxcontrib-jsmath==1.0.1 # via sphinx @@ -58,9 +58,9 @@ sphinxcontrib-log-cabinet==1.0.1 # via -r requirements/docs.in sphinxcontrib-qthelp==1.0.3 # via sphinx -sphinxcontrib-serializinghtml==1.1.4 +sphinxcontrib-serializinghtml==1.1.5 # via sphinx -urllib3==1.26.4 +urllib3==1.26.5 # via requests # The following packages are considered to be unsafe in a requirements file: diff --git a/requirements/typing.txt b/requirements/typing.txt index 0e342aa..fa04c8a 100644 --- a/requirements/typing.txt +++ b/requirements/typing.txt @@ -4,11 +4,11 @@ # # pip-compile requirements/typing.in # +mypy==0.910 + # via -r requirements/typing.in mypy-extensions==0.4.3 # via mypy -mypy==0.812 - # via -r requirements/typing.in -typed-ast==1.4.3 +toml==0.10.2 # via mypy typing-extensions==3.10.0.0 # via mypy diff --git a/src/markupsafe/__init__.py b/src/markupsafe/__init__.py index 98e2d1b..d1bf187 100644 --- a/src/markupsafe/__init__.py +++ b/src/markupsafe/__init__.py @@ -11,7 +11,7 @@ if t.TYPE_CHECKING: pass -__version__ = "2.0.2.dev0" +__version__ = "2.1.0.dev0" _striptags_re = re.compile(r"(<!--.*?-->|<[^>]*>)") @@ -102,9 +102,14 @@ class Markup(str): def __mod__(self, arg: t.Any) -> "Markup": if isinstance(arg, tuple): + # a tuple of arguments, each wrapped arg = tuple(_MarkupEscapeHelper(x, self.escape) for x in arg) - else: + elif hasattr(type(arg), "__getitem__") and not isinstance(arg, str): + # a mapping of arguments, wrapped arg = _MarkupEscapeHelper(arg, self.escape) + else: + # a single argument, wrapped with the helper and a tuple + arg = (_MarkupEscapeHelper(arg, self.escape),) return self.__class__(super().__mod__(arg)) diff --git a/tests/test_markupsafe.py b/tests/test_markupsafe.py index fcd9347..1d4ac2e 100644 --- a/tests/test_markupsafe.py +++ b/tests/test_markupsafe.py @@ -45,6 +45,12 @@ def test_html_interop(): assert result == "<strong><em>awesome</em></strong>" +@pytest.mark.parametrize("args", ["foo", 42, ("foo", 42)]) +def test_missing_interpol(args): + with pytest.raises(TypeError): + Markup("<em></em>") % args + + def test_tuple_interpol(): result = Markup("<em>%s:%s</em>") % ("<foo>", "<bar>") expect = Markup("<em><foo>:<bar></em>") |