| 1 | from pypy.interpreter.baseobjspace import W_Root |
| 2 | from pypy.interpreter.gateway import interp2app |
| 3 | from pypy.interpreter.typedef import TypeDef |
| 4 | |
| 5 | |
| 6 | class W_NoneObject(W_Root): |
| 7 | def unwrap(self, space): |
| 8 | return None |
| 9 | |
| 10 | @staticmethod |
| 11 | def descr_new(space, w_type): |
| 12 | "Create and return a new object. See help(type) for accurate signature." |
| 13 | return space.w_None |
| 14 | |
| 15 | def descr_bool(self, space): |
| 16 | return space.w_False |
| 17 | |
| 18 | def descr_repr(self, space): |
| 19 | return space.newtext('None') |
| 20 | |
| 21 | def descr_or(self, space, w_other): |
| 22 | w_builtins = space.getbuiltinmodule('builtins') |
| 23 | w_mod = space.call_method(w_builtins, '__import__', space.newtext("_pypy_generic_alias")) |
| 24 | w_union = space.getattr(w_mod, space.newtext("_create_union")) |
| 25 | w_union = space.getattr(w_mod, space.newtext("_create_union")) |
| 26 | return space.call_function(w_union, self, w_other) |
| 27 | |
| 28 | |
| 29 | W_NoneObject.w_None = W_NoneObject() |
| 30 | |
| 31 | W_NoneObject.typedef = TypeDef("NoneType", |
| 32 | __new__ = interp2app(W_NoneObject.descr_new), |
| 33 | __bool__ = interp2app(W_NoneObject.descr_bool), |
| 34 | __repr__ = interp2app(W_NoneObject.descr_repr), |
| 35 | ) |
| 36 | W_NoneObject.typedef.acceptable_as_base_class = False |