@@ -18,7 +18,7 @@ Noteworthy: None is the 'nil' object; Ellipsis represents '...' in slices.`
18
18
func init () {
19
19
methods := []* py.Method {
20
20
py .NewMethod ("__build_class__" , builtin___build_class__ , 0 , build_class_doc ),
21
- py .NewMethod ("__import__" , builtin___import__ , 0 , import_doc ),
21
+ py .NewMethod ("__import__" , py . InternalMethodImport , 0 , import_doc ),
22
22
py .NewMethod ("abs" , builtin_abs , 0 , abs_doc ),
23
23
// py.NewMethod("all", builtin_all, 0, all_doc),
24
24
// py.NewMethod("any", builtin_any, 0, any_doc),
@@ -34,7 +34,7 @@ func init() {
34
34
// py.NewMethod("exec", builtin_exec, 0, exec_doc),
35
35
// py.NewMethod("format", builtin_format, 0, format_doc),
36
36
py .NewMethod ("getattr" , builtin_getattr , 0 , getattr_doc ),
37
- // py.NewMethod("globals", builtin_globals, py.METH_NOARGS , globals_doc),
37
+ py .NewMethod ("globals" , py .InternalMethodGlobals , 0 , globals_doc ),
38
38
py .NewMethod ("hasattr" , builtin_hasattr , 0 , hasattr_doc ),
39
39
// py.NewMethod("hash", builtin_hash, 0, hash_doc),
40
40
// py.NewMethod("hex", builtin_hex, 0, hex_doc),
@@ -44,7 +44,7 @@ func init() {
44
44
// py.NewMethod("issubclass", builtin_issubclass, 0, issubclass_doc),
45
45
// py.NewMethod("iter", builtin_iter, 0, iter_doc),
46
46
py .NewMethod ("len" , builtin_len , 0 , len_doc ),
47
- // py.NewMethod("locals", builtin_locals, py.METH_NOARGS , locals_doc),
47
+ py .NewMethod ("locals" , py .InternalMethodLocals , 0 , locals_doc ),
48
48
// py.NewMethod("max", builtin_max, 0, max_doc),
49
49
// py.NewMethod("min", builtin_min, 0, min_doc),
50
50
py .NewMethod ("next" , builtin_next , 0 , next_doc ),
@@ -351,21 +351,6 @@ fromlist is not empty. Level is used to determine whether to perform
351
351
absolute or relative imports. 0 is absolute while a positive number
352
352
is the number of parent directories to search relative to the current module.`
353
353
354
- func builtin___import__ (self py.Object , args py.Tuple , kwargs py.StringDict ) py.Object {
355
- kwlist := []string {"name" , "globals" , "locals" , "fromlist" , "level" }
356
- var name py.Object
357
- var globals py.Object = py .NewStringDict ()
358
- var locals py.Object = py .NewStringDict ()
359
- var fromlist py.Object = py.Tuple {}
360
- var level py.Object = py .Int (0 )
361
-
362
- py .ParseTupleAndKeywords (args , kwargs , "U|OOOi:__import__" , kwlist , & name , & globals , & locals , & fromlist , & level )
363
- if fromlist == py .None {
364
- fromlist = py.Tuple {}
365
- }
366
- return py .ImportModuleLevelObject (string (name .(py.String )), globals .(py.StringDict ), locals .(py.StringDict ), fromlist .(py.Tuple ), int (level .(py.Int )))
367
- }
368
-
369
354
const ord_doc = `ord(c) -> integer
370
355
371
356
Return the integer ordinal of a one-character string.`
@@ -375,13 +360,13 @@ func builtin_ord(self, obj py.Object) py.Object {
375
360
switch x := obj .(type ) {
376
361
case py.Bytes :
377
362
size = len (x )
378
- if len ( x ) == 1 {
363
+ if size == 1 {
379
364
return py .Int (x [0 ])
380
365
}
381
366
case py.String :
382
- var rune rune
383
- rune , size = utf8 .DecodeRuneInString (string (x ))
384
- if len ( x ) == size && rune != utf8 .RuneError {
367
+ size = len ( x )
368
+ rune , runeSize : = utf8 .DecodeRuneInString (string (x ))
369
+ if size == runeSize && rune != utf8 .RuneError {
385
370
return py .Int (rune )
386
371
}
387
372
//case py.ByteArray:
@@ -396,7 +381,7 @@ func builtin_ord(self, obj py.Object) py.Object {
396
381
panic (py .ExceptionNewf (py .TypeError , "ord() expected string of length 1, but %s found" , obj .Type ().Name ))
397
382
}
398
383
399
- panic (py .ExceptionNewf (py .TypeError , "ord() expected a character, but string of length %zd found" , size ))
384
+ panic (py .ExceptionNewf (py .TypeError , "ord() expected a character, but string of length %d found" , size ))
400
385
}
401
386
402
387
const getattr_doc = `getattr(object, name[, default]) -> value
@@ -575,3 +560,11 @@ func builtin_chr(self py.Object, args py.Tuple) py.Object {
575
560
n := utf8 .EncodeRune (buf , rune (x ))
576
561
return py .String (buf [:n ])
577
562
}
563
+
564
+ const locals_doc = `locals() -> dictionary
565
+
566
+ Update and return a dictionary containing the current scope's local variables.`
567
+
568
+ const globals_doc = `globals() -> dictionary
569
+
570
+ Return the dictionary containing the current scope's global variables.`
0 commit comments