Skip to content

Commit

Permalink
drop support for python 3.8 (#464)
Browse files Browse the repository at this point in the history
  • Loading branch information
davidism authored Oct 6, 2024
2 parents b43c029 + 9372f38 commit f56c105
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 24 deletions.
1 change: 0 additions & 1 deletion .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ jobs:
- {python: '3.11'}
- {python: '3.10'}
- {python: '3.9'}
- {python: '3.8'}
- {name: PyPy, python: 'pypy-3.10', tox: pypy310}
steps:
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
Expand Down
2 changes: 1 addition & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Version 3.0.0

Unreleased

- Drop support for Python 3.7.
- Drop support for Python 3.7 and 3.8.
- Use modern packaging metadata with ``pyproject.toml`` instead of ``setup.cfg``.
:pr:`348`
- Change ``distutils`` imports to ``setuptools``. :pr:`399`
Expand Down
6 changes: 3 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ classifiers = [
"Topic :: Text Processing :: Markup :: HTML",
"Typing :: Typed",
]
requires-python = ">=3.8"
requires-python = ">=3.9"

[project.urls]
Donate = "https://palletsprojects.com/donate"
Expand All @@ -43,7 +43,7 @@ source = ["markupsafe", "tests"]
source = ["src", "*/site-packages"]

[tool.mypy]
python_version = "3.8"
python_version = "3.9"
files = ["src/markupsafe", "tests"]
show_error_codes = true
pretty = true
Expand All @@ -56,7 +56,7 @@ module = [
ignore_missing_imports = true

[tool.pyright]
pythonVersion = "3.8"
pythonVersion = "3.9"
include = ["src/markupsafe", "tests"]
typeCheckingMode = "basic"

Expand Down
35 changes: 17 additions & 18 deletions src/markupsafe/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import collections.abc as cabc
import string
import sys
import typing as t

try:
Expand All @@ -13,11 +12,13 @@
if t.TYPE_CHECKING:
import typing_extensions as te

class HasHTML(te.Protocol):
def __html__(self, /) -> str: ...

class TPEscape(te.Protocol):
def __call__(self, s: t.Any, /) -> Markup: ...
class _HasHTML(t.Protocol):
def __html__(self, /) -> str: ...


class _TPEscape(t.Protocol):
def __call__(self, s: t.Any, /) -> Markup: ...


def escape(s: t.Any, /) -> Markup:
Expand Down Expand Up @@ -130,13 +131,13 @@ def __new__(
def __html__(self, /) -> te.Self:
return self

def __add__(self, value: str | HasHTML, /) -> te.Self:
def __add__(self, value: str | _HasHTML, /) -> te.Self:
if isinstance(value, str) or hasattr(value, "__html__"):
return self.__class__(super().__add__(self.escape(value)))

return NotImplemented

def __radd__(self, value: str | HasHTML, /) -> te.Self:
def __radd__(self, value: str | _HasHTML, /) -> te.Self:
if isinstance(value, str) or hasattr(value, "__html__"):
return self.escape(value).__add__(self)

Expand Down Expand Up @@ -164,7 +165,7 @@ def __mod__(self, value: t.Any, /) -> te.Self:
def __repr__(self, /) -> str:
return f"{self.__class__.__name__}({super().__repr__()})"

def join(self, iterable: cabc.Iterable[str | HasHTML], /) -> te.Self:
def join(self, iterable: cabc.Iterable[str | _HasHTML], /) -> te.Self:
return self.__class__(super().join(map(self.escape, iterable)))

def split( # type: ignore[override]
Expand Down Expand Up @@ -291,13 +292,11 @@ def zfill(self, width: t.SupportsIndex, /) -> te.Self:
def casefold(self, /) -> te.Self:
return self.__class__(super().casefold())

if sys.version_info >= (3, 9):

def removeprefix(self, prefix: str, /) -> te.Self:
return self.__class__(super().removeprefix(prefix))
def removeprefix(self, prefix: str, /) -> te.Self:
return self.__class__(super().removeprefix(prefix))

def removesuffix(self, suffix: str) -> te.Self:
return self.__class__(super().removesuffix(suffix))
def removesuffix(self, suffix: str) -> te.Self:
return self.__class__(super().removesuffix(suffix))

def partition(self, sep: str, /) -> tuple[te.Self, te.Self, te.Self]:
left, sep, right = super().partition(sep)
Expand Down Expand Up @@ -331,8 +330,8 @@ def __html_format__(self, format_spec: str, /) -> te.Self:
class EscapeFormatter(string.Formatter):
__slots__ = ("escape",)

def __init__(self, escape: TPEscape) -> None:
self.escape: TPEscape = escape
def __init__(self, escape: _TPEscape) -> None:
self.escape: _TPEscape = escape
super().__init__()

def format_field(self, value: t.Any, format_spec: str) -> str:
Expand All @@ -358,9 +357,9 @@ class _MarkupEscapeHelper:

__slots__ = ("obj", "escape")

def __init__(self, obj: t.Any, escape: TPEscape) -> None:
def __init__(self, obj: t.Any, escape: _TPEscape) -> None:
self.obj: t.Any = obj
self.escape: TPEscape = escape
self.escape: _TPEscape = escape

def __getitem__(self, key: t.Any, /) -> te.Self:
return self.__class__(self.obj[key], self.escape)
Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tox]
envlist =
py3{13,12,11,10,9,8}
py3{13,12,11,10,9}
pypy310
style
typing
Expand Down

0 comments on commit f56c105

Please sign in to comment.