From 5ec432a6095fd7df2e3c076cb9aad98e5582c0c5 Mon Sep 17 00:00:00 2001 From: Jani Nikula Date: Sat, 28 Sep 2024 12:49:39 +0300 Subject: [PATCH] typing: use Optional[T] instead of T | None for Python 3.9 compatibility Although Python 3.9 supports built-in type hinting instead of having to import from typing, unfortunately the T | None syntax was only introduced in Python 3.10. Use Optional[T] instead for Python 3.9 compatibility. --- src/hawkmoth/__init__.py | 5 +++-- src/hawkmoth/ext/javadoc/__init__.py | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/hawkmoth/__init__.py b/src/hawkmoth/__init__.py index 7a05b24e..e6e2aac7 100644 --- a/src/hawkmoth/__init__.py +++ b/src/hawkmoth/__init__.py @@ -9,6 +9,7 @@ import glob import os +from typing import Optional from docutils import nodes from docutils.parsers.rst import directives @@ -35,8 +36,8 @@ class _AutoBaseDirective(SphinxDirective): } has_content = False - _domain: str | None = None - _docstring_types: list[type[docstring.Docstring]] | None = None + _domain: Optional[str] = None + _docstring_types: Optional[list[type[docstring.Docstring]]] = None def __display_parser_diagnostics(self, errors): # Map parser diagnostic level to Sphinx level name diff --git a/src/hawkmoth/ext/javadoc/__init__.py b/src/hawkmoth/ext/javadoc/__init__.py index 0b0f6823..218c5b74 100644 --- a/src/hawkmoth/ext/javadoc/__init__.py +++ b/src/hawkmoth/ext/javadoc/__init__.py @@ -2,6 +2,7 @@ # Licensed under the terms of BSD 2-Clause, see LICENSE for details. import re +from typing import Optional # The "operator" character, either \ or @, but not escaped with \ OP = r'(?[\\@])' @@ -86,7 +87,7 @@ class _block_with_end_command(_handler): """Paragraph with a dedicated command to end it. For example, @code/@endcode.""" - _end_command: str | None = None + _end_command: Optional[str] = None def end_command(self): """Get the name of the command that ends this paragraph.""" @@ -135,7 +136,7 @@ def header(self): class _field_list(_handler): """Paragraph which becomes a single field list item.""" - _field_name: str | None = None + _field_name: Optional[str] = None _indented_paragraph = True def field_name(self):