|
141 | 141 | def check_name(name): |
142 | 142 | assert all(i in _pin_name_chars for i in name), "pin `name` can only contain letters, digits, " \ |
143 | 143 | "minus sign and underscore" |
144 | | - assert name != 'use_strict', "'use_strict' is a reserve name, can't use as pin widget name" |
145 | | - assert name != '_strict', "'_strict' is a reserve name, can't use as pin widget name" |
146 | 144 |
|
147 | 145 |
|
148 | 146 | def _pin_output(single_input_return, scope, position): |
@@ -254,28 +252,28 @@ def use_strict(self): |
254 | 252 | Enable strict mode for getting pin widget value. |
255 | 253 | An AssertionError will be raised when try to get value of pin widgets that are currently not in the page. |
256 | 254 | """ |
257 | | - self._strict = True |
| 255 | + object.__setattr__(self, '_strict', True) |
258 | 256 |
|
259 | 257 | def __getattr__(self, name): |
260 | 258 | """__getattr__ is only invoked if the attribute wasn't found the usual ways""" |
261 | | - check_name(name) |
262 | | - return get_pin_value(name, self._strict) |
| 259 | + if name.startswith('__'): |
| 260 | + raise AttributeError('Pin object has no attribute %r' % name) |
| 261 | + return self.__getitem__(name) |
263 | 262 |
|
264 | 263 | def __getitem__(self, name): |
265 | | - return self.__getattr__(name) |
| 264 | + check_name(name) |
| 265 | + return get_pin_value(name, self._strict) |
266 | 266 |
|
267 | 267 | def __setattr__(self, name, value): |
268 | 268 | """ |
269 | 269 | __setattr__ will be invoked regardless of whether the attribute be found |
270 | 270 | """ |
271 | | - if name == '_strict': |
272 | | - return object.__setattr__(self, name, value) |
273 | | - |
| 271 | + assert name != 'use_strict', "'use_strict' is a reserve name, can't use as pin widget name" |
274 | 272 | check_name(name) |
275 | | - send_msg('pin_update', spec=dict(name=name, attributes={"value": value})) |
| 273 | + self.__setitem__(name, value) |
276 | 274 |
|
277 | 275 | def __setitem__(self, name, value): |
278 | | - self.__setattr__(name, value) |
| 276 | + send_msg('pin_update', spec=dict(name=name, attributes={"value": value})) |
279 | 277 |
|
280 | 278 |
|
281 | 279 | # pin widgets value getter (and setter). |
|
0 commit comments