Move TypeGuard to TYPE_CHECKING condition

This commit is contained in:
Veronica Berglyd Olsen
2023-08-08 23:14:35 +02:00
parent 5d817ae51f
commit 6e5d991cfe
2 changed files with 7 additions and 4 deletions
+3 -3
View File
@@ -30,7 +30,7 @@ import logging
import unicodedata import unicodedata
import xml.etree.ElementTree as ET import xml.etree.ElementTree as ET
from typing import Any, Literal, TypeGuard from typing import Any, Literal
from pathlib import Path from pathlib import Path
from datetime import datetime from datetime import datetime
from configparser import ConfigParser from configparser import ConfigParser
@@ -134,7 +134,7 @@ def checkPath(value: Any, default: Path) -> Path:
# Validator Functions # Validator Functions
# =============================================================================================== # # =============================================================================================== #
def isHandle(value: Any) -> TypeGuard[str]: def isHandle(value: Any) -> bool:
"""Check if a string is a valid novelWriter handle. """Check if a string is a valid novelWriter handle.
Note: This is case sensitive. Must be lower case! Note: This is case sensitive. Must be lower case!
""" """
@@ -148,7 +148,7 @@ def isHandle(value: Any) -> TypeGuard[str]:
return True return True
def isTitleTag(value: Any) -> TypeGuard[str]: def isTitleTag(value: Any) -> bool:
"""Check if a string is a valid title tag string.""" """Check if a string is a valid title tag string."""
if not isinstance(value, str): if not isinstance(value, str):
return False return False
+4 -1
View File
@@ -27,7 +27,7 @@ from __future__ import annotations
import random import random
import logging import logging
from typing import ItemsView, Iterator, KeysView, Literal, TypeGuard, ValuesView from typing import TYPE_CHECKING, ItemsView, Iterator, KeysView, Literal, ValuesView
from PyQt5.QtGui import QIcon, QPainter, QPainterPath, QPixmap, QColor from PyQt5.QtGui import QIcon, QPainter, QPainterPath, QPixmap, QColor
from PyQt5.QtCore import QRectF, Qt from PyQt5.QtCore import QRectF, Qt
@@ -35,6 +35,9 @@ from PyQt5.QtCore import QRectF, Qt
from novelwriter import CONFIG from novelwriter import CONFIG
from novelwriter.common import minmax, simplified from novelwriter.common import minmax, simplified
if TYPE_CHECKING: # pragma: no cover
from typing import TypeGuard # Requires Python 3.10
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)