Skip to content

Commit d63f135

Browse files
committed
Fix type checking issue in Python 3.9
1 parent 2a54b45 commit d63f135

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

  • {{ cookiecutter.pypi_package_name }}/{{ cookiecutter.python_package_name }}

{{ cookiecutter.pypi_package_name }}/{{ cookiecutter.python_package_name }}/config.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@
22

33
import json
44
import os
5+
{% if cookiecutter.use_alternative_union_syntax == "y" -%}
56
from typing import Any
7+
{%- else -%}
8+
from typing import Any, Optional
9+
{%- endif %}
610

711
import xdg.BaseDirectory # type: ignore
812

@@ -12,7 +16,13 @@
1216
logger = get_logger(__name__)
1317

1418

19+
{% if cookiecutter.use_alternative_union_syntax == "y" -%}
1520
def config_get(key: str, default: Any | None = None) -> Any | None:
21+
{%- else -%}
22+
def config_get(
23+
key: str, default: Optional[Any] = None
24+
) -> Optional[Any]:
25+
{%- endif %}
1626
"""Reads a config from the first level of a JSON file by key.
1727
1828
:param key: the name of the top-level JSON property.
@@ -74,7 +84,11 @@ def config_set(key: str, value: Any) -> None:
7484
logger.info('New value written')
7585

7686

87+
{% if cookiecutter.use_alternative_union_syntax == "y" -%}
7788
def config_dir(subdir: str | None = None) -> str:
89+
{%- else -%}
90+
def config_dir(subdir: Optional[str] = None) -> str:
91+
{%- endif %}
7892
"""Returns the configuration directory for this package.
7993
8094
Respects the XDG settings. Also creates the directory if it does

0 commit comments

Comments
 (0)