mirror of
https://github.com/getpelican/pelican.git
synced 2026-06-05 09:56:55 +02:00
Update code for Python 3.10+
This commit is contained in:
parent
2548bae70d
commit
8d61c0bdf7
5 changed files with 26 additions and 23 deletions
|
|
@ -266,7 +266,7 @@ class PrintSettings(argparse.Action):
|
|||
for setting in values:
|
||||
if setting in settings:
|
||||
# Only add newline between setting name and value if dict
|
||||
if isinstance(settings[setting], (dict, tuple, list)):
|
||||
if isinstance(settings[setting], dict | tuple | list):
|
||||
setting_format = "\n{}:\n{}"
|
||||
else:
|
||||
setting_format = "\n{}: {}"
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ import logging
|
|||
import os
|
||||
import re
|
||||
from html import unescape
|
||||
from typing import Any, Optional
|
||||
from typing import Any
|
||||
from urllib.parse import ParseResult, unquote, urljoin, urlparse, urlunparse
|
||||
|
||||
try:
|
||||
|
|
@ -45,7 +45,7 @@ class Content:
|
|||
|
||||
"""
|
||||
|
||||
default_template: Optional[str] = None
|
||||
default_template: str | None = None
|
||||
mandatory_properties: tuple[str, ...] = ()
|
||||
|
||||
@deprecated_attribute(old="filename", new="source_path", since=(3, 2, 0))
|
||||
|
|
@ -55,10 +55,10 @@ class Content:
|
|||
def __init__(
|
||||
self,
|
||||
content: str,
|
||||
metadata: Optional[dict[str, Any]] = None,
|
||||
settings: Optional[Settings] = None,
|
||||
source_path: Optional[str] = None,
|
||||
context: Optional[dict[Any, Any]] = None,
|
||||
metadata: dict[str, Any] | None = None,
|
||||
settings: Settings | None = None,
|
||||
source_path: str | None = None,
|
||||
context: dict[Any, Any] | None = None,
|
||||
):
|
||||
if metadata is None:
|
||||
metadata = {}
|
||||
|
|
@ -241,7 +241,7 @@ class Content:
|
|||
)
|
||||
return metadata
|
||||
|
||||
def _expand_settings(self, key: str, klass: Optional[str] = None) -> str:
|
||||
def _expand_settings(self, key: str, klass: str | None = None) -> str:
|
||||
if not klass:
|
||||
klass = self.__class__.__name__
|
||||
fq_key = (f"{klass}_{key}").upper()
|
||||
|
|
@ -281,10 +281,10 @@ class Content:
|
|||
# XXX Put this in a different location.
|
||||
if what in {"filename", "static", "attach"}:
|
||||
|
||||
def _get_linked_content(key: str, url: ParseResult) -> Optional[Content]:
|
||||
def _get_linked_content(key: str, url: ParseResult) -> Content | None:
|
||||
nonlocal value
|
||||
|
||||
def _find_path(path: str) -> Optional[Content]:
|
||||
def _find_path(path: str) -> Content | None:
|
||||
if path.startswith("/"):
|
||||
path = path[1:]
|
||||
else:
|
||||
|
|
@ -494,9 +494,7 @@ class Content:
|
|||
else:
|
||||
return self.default_template
|
||||
|
||||
def get_relative_source_path(
|
||||
self, source_path: Optional[str] = None
|
||||
) -> Optional[str]:
|
||||
def get_relative_source_path(self, source_path: str | None = None) -> str | None:
|
||||
"""Return the relative path (from the content path) to the given
|
||||
source_path.
|
||||
|
||||
|
|
|
|||
|
|
@ -7,7 +7,6 @@ from collections import defaultdict
|
|||
from functools import partial
|
||||
from itertools import chain, groupby
|
||||
from operator import attrgetter
|
||||
from typing import Optional
|
||||
|
||||
from jinja2 import (
|
||||
BaseLoader,
|
||||
|
|
@ -158,7 +157,7 @@ class Generator:
|
|||
return False
|
||||
|
||||
def get_files(
|
||||
self, paths, exclude: Optional[list[str]] = None, extensions=None
|
||||
self, paths, exclude: list[str] | None = None, extensions=None
|
||||
) -> set[str]:
|
||||
"""Return a list of files to use, based on rules
|
||||
|
||||
|
|
@ -253,7 +252,7 @@ class Generator:
|
|||
# return the name of the class for logging purposes
|
||||
return self.__class__.__name__
|
||||
|
||||
def _check_disabled_readers(self, paths, exclude: Optional[list[str]]) -> None:
|
||||
def _check_disabled_readers(self, paths, exclude: list[str] | None) -> None:
|
||||
"""Log warnings for files that would have been processed by disabled readers."""
|
||||
for fil in self.get_files(
|
||||
paths, exclude=exclude, extensions=self.readers.disabled_extensions
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ import sys
|
|||
from os.path import isabs
|
||||
from pathlib import Path
|
||||
from types import ModuleType
|
||||
from typing import Any, Optional
|
||||
from typing import Any
|
||||
|
||||
from pelican.log import LimitFilter
|
||||
from pelican.paginator import PaginationRule
|
||||
|
|
@ -185,7 +185,7 @@ PYGMENTS_RST_OPTIONS = None
|
|||
|
||||
|
||||
def read_settings(
|
||||
path: Optional[str] = None, override: Optional[Settings] = None
|
||||
path: str | None = None, override: Settings | None = None
|
||||
) -> Settings:
|
||||
settings = override or {}
|
||||
|
||||
|
|
@ -230,7 +230,7 @@ def read_settings(
|
|||
return settings
|
||||
|
||||
|
||||
def get_settings_from_module(module: Optional[ModuleType] = None) -> Settings:
|
||||
def get_settings_from_module(module: ModuleType | None = None) -> Settings:
|
||||
"""Loads settings from a module, returns a dictionary."""
|
||||
|
||||
context = {}
|
||||
|
|
|
|||
|
|
@ -11,7 +11,14 @@ import shutil
|
|||
import traceback
|
||||
import unicodedata
|
||||
import urllib
|
||||
from collections.abc import Collection, Generator, Hashable, Iterable, Sequence
|
||||
from collections.abc import (
|
||||
Callable,
|
||||
Collection,
|
||||
Generator,
|
||||
Hashable,
|
||||
Iterable,
|
||||
Sequence,
|
||||
)
|
||||
from contextlib import contextmanager
|
||||
from functools import partial
|
||||
from html import entities
|
||||
|
|
@ -21,7 +28,6 @@ from operator import attrgetter
|
|||
from typing import (
|
||||
TYPE_CHECKING,
|
||||
Any,
|
||||
Callable,
|
||||
)
|
||||
|
||||
import dateutil.parser
|
||||
|
|
@ -234,7 +240,7 @@ def get_date(string: str) -> datetime.datetime:
|
|||
|
||||
|
||||
@contextmanager
|
||||
def pelican_open(filename: str, mode: str = "r") -> Generator[str, None, None]:
|
||||
def pelican_open(filename: str, mode: str = "r") -> Generator[str]:
|
||||
"""Open a file and return its content"""
|
||||
|
||||
# utf-8-sig will clear any BOM if present
|
||||
|
|
@ -932,7 +938,7 @@ def maybe_pluralize(count: int, singular: str, plural: str) -> str:
|
|||
@contextmanager
|
||||
def temporary_locale(
|
||||
temp_locale: str | None = None, lc_category: int = locale.LC_ALL
|
||||
) -> Generator[None, None, None]:
|
||||
) -> Generator[None]:
|
||||
"""
|
||||
Enable code to run in a context with a temporary locale
|
||||
Resets the locale back when exiting context.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue