Move TypeGuard to TYPE_CHECKING condition
This commit is contained in:
@@ -30,7 +30,7 @@ import logging
|
||||
import unicodedata
|
||||
import xml.etree.ElementTree as ET
|
||||
|
||||
from typing import Any, Literal, TypeGuard
|
||||
from typing import Any, Literal
|
||||
from pathlib import Path
|
||||
from datetime import datetime
|
||||
from configparser import ConfigParser
|
||||
@@ -134,7 +134,7 @@ def checkPath(value: Any, default: Path) -> Path:
|
||||
# Validator Functions
|
||||
# =============================================================================================== #
|
||||
|
||||
def isHandle(value: Any) -> TypeGuard[str]:
|
||||
def isHandle(value: Any) -> bool:
|
||||
"""Check if a string is a valid novelWriter handle.
|
||||
Note: This is case sensitive. Must be lower case!
|
||||
"""
|
||||
@@ -148,7 +148,7 @@ def isHandle(value: Any) -> TypeGuard[str]:
|
||||
return True
|
||||
|
||||
|
||||
def isTitleTag(value: Any) -> TypeGuard[str]:
|
||||
def isTitleTag(value: Any) -> bool:
|
||||
"""Check if a string is a valid title tag string."""
|
||||
if not isinstance(value, str):
|
||||
return False
|
||||
|
||||
@@ -27,7 +27,7 @@ from __future__ import annotations
|
||||
import random
|
||||
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.QtCore import QRectF, Qt
|
||||
@@ -35,6 +35,9 @@ from PyQt5.QtCore import QRectF, Qt
|
||||
from novelwriter import CONFIG
|
||||
from novelwriter.common import minmax, simplified
|
||||
|
||||
if TYPE_CHECKING: # pragma: no cover
|
||||
from typing import TypeGuard # Requires Python 3.10
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user