From 4b654a5f4d7e7dd13c735d47d1cd7a919d84f47c Mon Sep 17 00:00:00 2001 From: Falko Schindler Date: Fri, 1 Dec 2023 13:54:56 +0100 Subject: [PATCH] fix for Python 3.8 --- website/documentation/content/doc/api.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/website/documentation/content/doc/api.py b/website/documentation/content/doc/api.py index 09ab7ea49..26babe8ba 100644 --- a/website/documentation/content/doc/api.py +++ b/website/documentation/content/doc/api.py @@ -1,5 +1,4 @@ from __future__ import annotations -from typing import Any import inspect import sys @@ -7,7 +6,7 @@ from copy import deepcopy from pathlib import Path from types import ModuleType -from typing import Callable, Dict, Optional, Union, overload +from typing import Any, Callable, Dict, Optional, Union, overload from nicegui import app as nicegui_app from nicegui import ui as nicegui_ui @@ -21,7 +20,7 @@ def get_page(documentation: ModuleType) -> DocumentationPage: """Return the documentation page for the given documentation module.""" - target_name = documentation.__name__.split('.')[-1].removesuffix('_documentation') + target_name = _removesuffix(documentation.__name__.split('.')[-1], '_documentation') assert target_name in registry, f'Documentation page {target_name} does not exist' return registry[target_name] @@ -30,7 +29,7 @@ def _get_current_page() -> DocumentationPage: frame = sys._getframe(2) # pylint: disable=protected-access module = inspect.getmodule(frame) assert module is not None and module.__file__ is not None - name = Path(module.__file__).stem.removesuffix('_documentation') + name = _removesuffix(Path(module.__file__).stem, '_documentation') if name not in registry: registry[name] = DocumentationPage(name=name) return registry[name] @@ -134,3 +133,10 @@ def _find_attribute(obj: Any, name: str) -> Optional[str]: if attr.lower().replace('_', '') == name.lower().replace('_', ''): return attr return None + + +def _removesuffix(string: str, suffix: str) -> str: + # NOTE: Remove this once we drop Python 3.8 support + if string.endswith(suffix): + return string[:-len(suffix)] + return string