Skip to content

Commit

Permalink
Removes remaining mentions of 3.8
Browse files Browse the repository at this point in the history
Updates isort config. Removes some more PY2 cruft.
  • Loading branch information
Daverball committed Dec 28, 2023
1 parent 83fc1af commit 13eaf00
Show file tree
Hide file tree
Showing 9 changed files with 22 additions and 50 deletions.
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Chameleon is an HTML/XML template engine for `Python
<http://www.python.org>`_. It uses the *page templates* language.

You can use it in any Python application with just about any
version of Python (3.8+ and up, plus `pypy 3
version of Python (3.9+ and up, plus `pypy 3
<http://pypy.org>`_).

Visit the `documentation <https://chameleon.readthedocs.io/en/latest/>`_
Expand Down
9 changes: 4 additions & 5 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,10 @@ ignore =
[isort]
force_single_line = True
combine_as_imports = True
sections = FUTURE,STDLIB,THIRDPARTY,ZOPE,FIRSTPARTY,LOCALFOLDER
known_third_party = six, docutils, pkg_resources, pytz
known_zope =
known_first_party =
default_section = ZOPE
sections = FUTURE,STDLIB,THIRDPARTY,FIRSTPARTY,LOCALFOLDER
known_first_party = chameleon
extra_standard_library = _typeshed, typing_extensions
default_section = THIRDPARTY
line_length = 79
lines_after_imports = 2

Expand Down
1 change: 0 additions & 1 deletion src/chameleon/astutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
from collections.abc import Callable
from collections.abc import MutableMapping
from typing import TypeVar

from typing_extensions import TypeAlias

_F = TypeVar('_F', bound=Callable[..., Any])
Expand Down
21 changes: 9 additions & 12 deletions src/chameleon/compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,6 @@
from chameleon.utils import safe_native


long = int

log = logging.getLogger('chameleon.compiler')

COMPILER_INTERNALS_OR_DISALLOWED = {
Expand All @@ -68,7 +66,6 @@
"str",
"int",
"float",
"long",
"len",
"bool",
"None",
Expand Down Expand Up @@ -155,9 +152,9 @@ def indent(s):


emit_convert = template(is_func=True,
func_args=('target', 'encoded', 'str', 'long', 'type',
func_args=('target', 'encoded', 'str', 'type',
'default_marker', 'default'),
func_defaults=(bytes, str, long, type, None),
func_defaults=(bytes, str, type, None),
source=r"""
if target is None:
pass
Expand All @@ -169,7 +166,7 @@ def indent(s):
if __tt is encoded:
target = decode(target)
elif __tt is not str:
if __tt is int or __tt is float or __tt is long:
if __tt is int or __tt is float:
target = str(target)
else:
render = getattr(target, "__html__", None)
Expand All @@ -189,8 +186,8 @@ def indent(s):

emit_func_convert = template(
is_func=True, func_args=(
'func', 'encoded', 'str', 'long', 'type'), func_defaults=(
bytes, str, long, type), source=r"""
'func', 'encoded', 'str', 'type'), func_defaults=(
bytes, str, type), source=r"""
def func(target):
if target is None:
return
Expand All @@ -200,7 +197,7 @@ def func(target):
if __tt is encoded:
target = decode(target)
elif __tt is not str:
if __tt is int or __tt is float or __tt is long:
if __tt is int or __tt is float:
target = str(target)
else:
render = getattr(target, "__html__", None)
Expand Down Expand Up @@ -237,8 +234,8 @@ def func(target):

emit_func_convert_and_escape = template(
is_func=True,
func_args=('func', 'str', 'long', 'type', 'encoded'),
func_defaults=(str, long, type, bytes,),
func_args=('func', 'str', 'type', 'encoded'),
func_defaults=(str, type, bytes,),
source=r"""
def func(target, quote, quote_entity, default, default_marker):
if target is None:
Expand All @@ -252,7 +249,7 @@ def func(target, quote, quote_entity, default, default_marker):
if __tt is encoded:
target = decode(target)
elif __tt is not str:
if __tt is int or __tt is float or __tt is long:
if __tt is int or __tt is float:
return str(target)
render = getattr(target, "__html__", None)
if render is None:
Expand Down
15 changes: 1 addition & 14 deletions src/chameleon/tales.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
split_parts = re.compile(r'(?<!\\)\|')
match_prefix = re.compile(r'^\s*([a-z][a-z0-9\-_]*):').match
re_continuation = re.compile(r'\\\s*$', re.MULTILINE)
exc_clear = getattr(sys, "exc_clear", None)


def resolve_global(value):
Expand All @@ -48,8 +47,6 @@ def test(expression, engine=None, **env):
module = ast.Module(body)
module = ast.fix_missing_locations(module)
env['rcontext'] = {}
if exc_clear is not None:
env['__exc_clear'] = exc_clear
source = TemplateCodeGenerator(module).code
code = compile(source, '<string>', 'exec')
exec(code, env)
Expand Down Expand Up @@ -159,17 +156,7 @@ def __call__(self, target, engine):
elts=map(resolve_global, self.exceptions),
ctx=ast.Load()),
name=None,
body=body if exc_clear is None else body + [
ast.Expr(
ast.Call(
func=load("__exc_clear"),
args=[],
keywords=[],
starargs=None,
kwargs=None,
)
)
],
body=body,
)],
)]

Expand Down
15 changes: 4 additions & 11 deletions src/chameleon/template.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,26 +36,19 @@


if TYPE_CHECKING:
from _typeshed import StrPath
from abc import abstractmethod
from collections.abc import Callable
from collections.abc import Collection

from _typeshed import StrPath

from chameleon.compiler import ExpressionEngine


try:
RecursionError
except NameError:
RecursionError = RuntimeError


def get_package_versions() -> list[tuple[str, str]]:
if sys.version_info < (3, 10):
import importlib_metadata
else:
if sys.version_info >= (3, 10):
import importlib.metadata as importlib_metadata
else:
import importlib_metadata

versions = {
x: importlib_metadata.version(x)
Expand Down
1 change: 0 additions & 1 deletion src/chameleon/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
if TYPE_CHECKING:
from collections.abc import Callable
from collections.abc import Collection

from typing_extensions import TypeAlias

from chameleon.tokenize import Token
Expand Down
1 change: 0 additions & 1 deletion src/chameleon/zpt/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
if TYPE_CHECKING:
from collections.abc import Mapping
from collections.abc import Sequence

from typing_extensions import TypeAlias

_FormatsMapping: TypeAlias = Mapping[str, type[template.PageTemplateFile]]
Expand Down
7 changes: 3 additions & 4 deletions src/chameleon/zpt/template.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,10 @@


if TYPE_CHECKING:
from _typeshed import StrPath
from collections.abc import Callable
from collections.abc import Collection
from collections.abc import Iterable

from _typeshed import StrPath
from typing_extensions import Unpack

from chameleon.types import AnyTranslationFunction
Expand Down Expand Up @@ -216,8 +215,8 @@ def translate(msgid, domain=None, mapping=None, default=None,
# so it is itself not callable, we don't really care, since we only
# ever use it as a descriptor, but to be able to override this with
# an instance attribute we can't declare this as a descriptor and
# since we only need this ignore in 3.8 and 3.9 we will get an unused
# ignore error instead above
# since we only need this ignore in 3.9 we will get an unused ignore
# error instead above, so we use this version check to avoid that
translate = staticmethod(simple_translate) # type: ignore[assignment]

encoding: str | None = None
Expand Down

0 comments on commit 13eaf00

Please sign in to comment.