Skip to content

Commit

Permalink
checkpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
aucampia committed Mar 23, 2023
1 parent ba44860 commit ea12ccc
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 10 deletions.
3 changes: 2 additions & 1 deletion examples/resource_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
bill.add(RDF.type, FOAF.Agent)
bill.set(RDFS.label, Literal("Bill"))

bill.add(FOAF.knows, bob)
# type error: Argument 2 to "add" of "Resource" has incompatible type "Resource"; expected "Node" [arg-type]
bill.add(FOAF.knows, bob) # type: ignore[arg-type]

# Resources returned when querying are 'auto-boxed' as resources:
print(f"Bill knows: {bill.value(FOAF.knows).value(FOAF.name)}")
Expand Down
9 changes: 8 additions & 1 deletion rdflib/plugins/parsers/jsonld.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,14 @@ def to_rdf(
data: Any,
dataset: Graph,
base: Optional[str] = None,
context_data: Optional[bool] = None,
context_data: Optional[
Union[
List[str],
List[Union[Dict[str, Any], str, None]],
Dict[str, Any],
str,
]
] = None,
version: Optional[float] = None,
generalized_rdf: bool = False,
allow_lists_of_lists: Optional[bool] = None,
Expand Down
28 changes: 20 additions & 8 deletions rdflib/plugins/shared/jsonld/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class Defined(int):
class Context(object):
def __init__(
self,
source: Optional[Any] = None,
source: Optional[Union[str, Dict[str, Any], List[str]]] = None,
base: Optional[str] = None,
version: Optional[float] = None,
):
Expand Down Expand Up @@ -388,20 +388,30 @@ def to_symbol(self, iri: str) -> Optional[str]:

def load(
self,
source: Optional[Union[List[Any], Any]],
source: Optional[
Union[
List[str],
List[Union[Dict[str, Any], str, None]],
Dict[str, Any],
str,
]
],
base: Optional[str] = None,
referenced_contexts: Set[Any] = None,
):
self.active = True
sources: List[Any] = []
sources: List[Tuple[Optional[str], Union[Dict[str, Any], str, None]]] = []
# "Union[List[Union[Dict[str, Any], str]], List[Dict[str, Any]], List[str]]" : expression
# "Union[List[Dict[str, Any]], Dict[str, Any], List[str], str]" : variable
source = source if isinstance(source, list) else [source]
referenced_contexts = referenced_contexts or set()
self._prep_sources(base, source, sources, referenced_contexts)
for source_url, source in sources:
if source is None:
self._clear()
else:
self._read_source(source, source_url, referenced_contexts)
# type error: Argument 1 to "_read_source" of "Context" has incompatible type "Union[Dict[str, Any], str]"; expected "Dict[str, Any]"
self._read_source(source, source_url, referenced_contexts) # type: ignore[arg-type]

def _accept_term(self, key: str) -> bool:
if self.version < 1.1:
Expand All @@ -414,8 +424,8 @@ def _accept_term(self, key: str) -> bool:
def _prep_sources(
self,
base: Optional[str],
inputs: List[Any],
sources: List[Any],
inputs: Union[List[Union[Dict[str, Any], str, None]], List[str]],
sources: List[Tuple[Optional[str], Union[Dict[str, Any], str, None]]],
referenced_contexts: Set[str],
in_source_url: Optional[str] = None,
):
Expand All @@ -442,10 +452,12 @@ def _prep_sources(
if isinstance(source, dict):
if CONTEXT in source:
source = source[CONTEXT]
source = source if isinstance(source, list) else [source]
# type ignore: Incompatible types in assignment (expression has type "List[Union[Dict[str, Any], str, None]]", variable has type "Union[Dict[str, Any], str, None]")
source = source if isinstance(source, list) else [source] # type: ignore[assignment]

if isinstance(source, list):
self._prep_sources(
# type error: Statement is unreachable
self._prep_sources( # type: ignore[unreachable]
new_base, source, sources, referenced_contexts, source_url
)
else:
Expand Down

0 comments on commit ea12ccc

Please sign in to comment.