MCPcopy Index your code
hub / github.com/numpy/numpy / BagObj

Class BagObj

numpy/lib/_npyio_impl.py:50–97  ·  view source on GitHub ↗

BagObj(obj) Convert attribute look-ups to getitems on the object passed in. Parameters ---------- obj : class instance Object on which attribute look-up is performed. Examples -------- >>> import numpy as np >>> from numpy.lib._npyio_impl import BagObj

Source from the content-addressed store, hash-verified

48
49
50class BagObj:
51 """
52 BagObj(obj)
53
54 Convert attribute look-ups to getitems on the object passed in.
55
56 Parameters
57 ----------
58 obj : class instance
59 Object on which attribute look-up is performed.
60
61 Examples
62 --------
63 >>> import numpy as np
64 >>> from numpy.lib._npyio_impl import BagObj as BO
65 >>> class BagDemo:
66 ... def __getitem__(self, key): # An instance of BagObj(BagDemo)
67 ... # will call this method when any
68 ... # attribute look-up is required
69 ... result = "Doesn't matter what you want, "
70 ... return result + "you're gonna get this"
71 ...
72 >>> demo_obj = BagDemo()
73 >>> bagobj = BO(demo_obj)
74 >>> bagobj.hello_there
75 "Doesn't matter what you want, you're gonna get this"
76 >>> bagobj.I_can_be_anything
77 "Doesn't matter what you want, you're gonna get this"
78
79 """
80
81 def __init__(self, obj):
82 # Use weakref to make NpzFile objects collectable by refcount
83 self._obj = weakref.proxy(obj)
84
85 def __getattribute__(self, key):
86 try:
87 return object.__getattribute__(self, '_obj')[key]
88 except KeyError:
89 raise AttributeError(key) from None
90
91 def __dir__(self):
92 """
93 Enables dir(bagobj) to list the files in an NpzFile.
94
95 This also enables tab-completion in an interpreter or IPython.
96 """
97 return list(object.__getattribute__(self, '_obj').keys())
98
99
100def zipfile_factory(file, *args, **kwargs):

Callers 1

__init__Method · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…