Skip to content

Commit b431380

Browse files
committed
feat(builtins): NotImplemented
1 parent c34fa87 commit b431380

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

Objects/notimplementedobject.nim

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import ./pyobject
2+
import ./stringobject
3+
4+
declarePyType NotImplemented(tpToken):
5+
discard
6+
7+
let pyNotImplemented* = newPyNotImplementedSimple() ## singleton
8+
9+
proc isNotImplemented*(obj: PyObject): bool =
10+
obj.id == pyNotImplemented.id
11+
12+
proc dollar(self: PyNotImplementedObject): string = "NotImplemented"
13+
method `$`*(self: PyNotImplementedObject): string =
14+
self.dollar
15+
16+
implNotImplementedMagic repr:
17+
newPyString self.dollar
18+

Objects/pyobjectBase.nim

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ type
1010
NULL,
1111
Object,
1212
None,
13+
NotImplemented,
1314
BaseError, # exception
1415
Int,
1516
Float,

Python/bltinmodule.nim

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import strformat
22
{.used.} # this module contains toplevel code, so never `importButNotUsed`
33
import neval
44
import builtindict
5-
import ../Objects/[bundle, typeobject, methodobject, descrobject, funcobject]
5+
import ../Objects/[bundle, typeobject, methodobject, descrobject, funcobject, notimplementedobject]
66
import ../Utils/[utils, macroutils, compat]
77

88

@@ -106,6 +106,7 @@ implBltinFunc buildClass(funcObj: PyFunctionObject, name: PyStrObject), "__build
106106
tpMagic(Type, new)(@[pyTypeObjectType, name, newPyTuple(@[]), f.toPyDict()])
107107

108108

109+
registerBltinObject("NotImplemented", pyNotImplemented)
109110
registerBltinObject("None", pyNone)
110111
registerBltinObject("type", pyTypeObjectType)
111112
registerBltinObject("range", pyRangeObjectType)

0 commit comments

Comments
 (0)