Skip to content

Commit 13981ac

Browse files
mokeyishmichaelmior
authored andcommitted
Add typings for IDE autocomplete
1 parent c94179c commit 13981ac

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

jsonpath_ng/jsonpath.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
from typing import List, Optional
13
import logging
24
from itertools import * # noqa
35
from jsonpath_ng.lexer import JsonPathLexer
@@ -20,7 +22,7 @@ class JSONPath:
2022
JSONPath semantics.
2123
"""
2224

23-
def find(self, data):
25+
def find(self, data) -> List[DatumInContext]:
2426
"""
2527
All `JSONPath` types support `find()`, which returns an iterable of `DatumInContext`s.
2628
They keep track of the path followed to the current location, so if the calling code
@@ -99,7 +101,7 @@ def wrap(cls, data):
99101
else:
100102
return cls(data)
101103

102-
def __init__(self, value, path=None, context=None):
104+
def __init__(self, value, path: Optional[JSONPath]=None, context: Optional[DatumInContext]=None):
103105
self.value = value
104106
self.path = path or This()
105107
self.context = None if context is None else DatumInContext.wrap(context)
@@ -113,7 +115,7 @@ def in_context(self, context, path):
113115
return DatumInContext(value=self.value, path=path, context=context)
114116

115117
@property
116-
def full_path(self):
118+
def full_path(self) -> JSONPath:
117119
return self.path if self.context is None else self.context.full_path.child(self.path)
118120

119121
@property
@@ -193,7 +195,7 @@ class Root(JSONPath):
193195
The root is the topmost datum without any context attached.
194196
"""
195197

196-
def find(self, data):
198+
def find(self, data) -> List[DatumInContext]:
197199
if not isinstance(data, DatumInContext):
198200
return [DatumInContext(data, path=Root(), context=None)]
199201
else:

jsonpath_ng/parser.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def __init__(self, debug=False, lexer_class=None):
5353
start = start_symbol,
5454
errorlog = logger)
5555

56-
def parse(self, string, lexer = None):
56+
def parse(self, string, lexer = None) -> JSONPath:
5757
lexer = lexer or self.lexer_class()
5858
return self.parse_token_stream(lexer.tokenize(string))
5959

0 commit comments

Comments
 (0)