Skip to content

Commit

Permalink
typing: use Optional[T] instead of T | None for Python 3.9 compatibility
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jnikula committed Sep 30, 2024
1 parent 706bb45 commit 5ec432a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
5 changes: 3 additions & 2 deletions src/hawkmoth/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import glob
import os
from typing import Optional

from docutils import nodes
from docutils.parsers.rst import directives
Expand All @@ -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
Expand Down
5 changes: 3 additions & 2 deletions src/hawkmoth/ext/javadoc/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'(?<!\\)(?P<op>[\\@])'
Expand Down Expand Up @@ -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."""
Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit 5ec432a

Please sign in to comment.