2222from .patch import JSONPatch
2323
2424if TYPE_CHECKING :
25+ from jsonpath import CompoundJSONPath
26+ from jsonpath import JSONPath
2527 from jsonpath import JSONPathEnvironment
2628 from jsonpath import JSONPathMatch
2729 from jsonpath import JSONPointer
@@ -191,7 +193,7 @@ def take(self, n: int) -> Query:
191193
192194 def select (
193195 self ,
194- * expressions : str ,
196+ * expressions : Union [ str , JSONPath , CompoundJSONPath ] ,
195197 projection : Projection = Projection .RELATIVE ,
196198 ) -> Iterable [object ]:
197199 """Query projection using relative JSONPaths.
@@ -217,7 +219,7 @@ def select(
217219 def _select (
218220 self ,
219221 match : JSONPathMatch ,
220- expressions : Tuple [str , ...],
222+ expressions : Tuple [Union [ str , JSONPath , CompoundJSONPath ] , ...],
221223 projection : Projection ,
222224 ) -> object :
223225 if isinstance (match .obj , str ):
@@ -232,20 +234,21 @@ def _select(
232234 patch = JSONPatch ()
233235
234236 for expr in expressions :
235- self ._patch (match , expr , patch , projection )
237+ path = self ._env .compile (expr ) if isinstance (expr , str ) else expr
238+ self ._patch (match , path , patch , projection )
236239
237240 return _fix_sparse_arrays (patch .apply (obj ))
238241
239242 def _patch (
240243 self ,
241244 match : JSONPathMatch ,
242- expr : str ,
245+ path : Union [ JSONPath , CompoundJSONPath ] ,
243246 patch : JSONPatch ,
244247 projection : Projection ,
245248 ) -> None :
246249 root_pointer = match .pointer ()
247250
248- for rel_match in self . _env . finditer (expr , match .obj ): # type: ignore
251+ for rel_match in path . finditer (match .obj ): # type: ignore
249252 if projection == Projection .FLAT :
250253 patch .addap ("/-" , rel_match .obj )
251254 elif projection == Projection .ROOT :
0 commit comments