File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -2211,6 +2211,11 @@ def keys(self):
22112211
22122212 return ops .keys (self )
22132213
2214+ def get (self , key , default = None ):
2215+ import opto .trace .operators as ops
2216+
2217+ return ops .get (self , node (key ), node (default ))
2218+
22142219 def pop (self , __index = - 1 ):
22152220 # python does hidden type checks
22162221 import opto .trace .operators as ops
Original file line number Diff line number Diff line change @@ -430,6 +430,14 @@ def values(x: Dict):
430430 return [k for k in x .values ()]
431431
432432
433+ @bundle ()
434+ def get (x : Any , key : Any , default : Any = None ):
435+ """Return the value for key if key is in x, else default."""
436+ if not hasattr (x , "get" ):
437+ raise AttributeError (f"{ type (x )} object has no attribute 'get'." )
438+ return x .get (key , default )
439+
440+
433441# dict in-place operators
434442
435443
You can’t perform that action at this time.
0 commit comments