summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIwan Aucamp <aucampia@gmail.com>2021-12-11 14:33:39 +0100
committerveyndan <veyndan@gmail.com>2021-12-18 12:16:51 +0100
commitb0febd6fa436837c148aeb051aee6928f77f082a (patch)
treea10572d75170411d8adc578e0212e6bc32743152
parentf6b1f7795ea84d307abd74f88ad005ee3928e732 (diff)
downloadrdflib-b0febd6fa436837c148aeb051aee6928f77f082a.tar.gz
More typing for rdflib.term.Literal
_value needs an explicit type and also added types for: - `lexical_or_value` - `datatype` - `normalize`
-rw-r--r--rdflib/term.py12
1 files changed, 7 insertions, 5 deletions
diff --git a/rdflib/term.py b/rdflib/term.py
index e9943bbc..181824f6 100644
--- a/rdflib/term.py
+++ b/rdflib/term.py
@@ -63,7 +63,7 @@ from urllib.parse import urljoin
from urllib.parse import urlparse
from decimal import Decimal
-from typing import TYPE_CHECKING, Dict, Callable, Optional, Union, Type
+from typing import TYPE_CHECKING, Any, Dict, Callable, Optional, Union, Type
if TYPE_CHECKING:
from .paths import AlternativePath, InvPath, NegatedPath, SequencePath, Path
@@ -532,14 +532,16 @@ class Literal(Identifier):
"""
+ _value: Any
+
__slots__ = ("_language", "_datatype", "_value")
def __new__(
cls,
- lexical_or_value,
+ lexical_or_value: Any,
lang: Optional[str] = None,
- datatype=None,
- normalize=None,
+ datatype: Optional[str] = None,
+ normalize: Optional[bool] = None,
):
if lang == "":
@@ -602,7 +604,7 @@ class Literal(Identifier):
lexical_or_value = _strip_and_collapse_whitespace(lexical_or_value)
try:
- inst = str.__new__(cls, lexical_or_value)
+ inst: Literal = str.__new__(cls, lexical_or_value)
except UnicodeDecodeError:
inst = str.__new__(cls, lexical_or_value, "utf-8")