@@ -18,7 +18,7 @@ Noteworthy: None is the 'nil' object; Ellipsis represents '...' in slices.`
1818func init () {
1919 methods := []* py.Method {
2020 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 ),
2222 py .NewMethod ("abs" , builtin_abs , 0 , abs_doc ),
2323 // py.NewMethod("all", builtin_all, 0, all_doc),
2424 // py.NewMethod("any", builtin_any, 0, any_doc),
@@ -34,7 +34,7 @@ func init() {
3434 // py.NewMethod("exec", builtin_exec, 0, exec_doc),
3535 // py.NewMethod("format", builtin_format, 0, format_doc),
3636 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 ),
3838 py .NewMethod ("hasattr" , builtin_hasattr , 0 , hasattr_doc ),
3939 // py.NewMethod("hash", builtin_hash, 0, hash_doc),
4040 // py.NewMethod("hex", builtin_hex, 0, hex_doc),
@@ -44,7 +44,7 @@ func init() {
4444 // py.NewMethod("issubclass", builtin_issubclass, 0, issubclass_doc),
4545 // py.NewMethod("iter", builtin_iter, 0, iter_doc),
4646 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 ),
4848 // py.NewMethod("max", builtin_max, 0, max_doc),
4949 // py.NewMethod("min", builtin_min, 0, min_doc),
5050 py .NewMethod ("next" , builtin_next , 0 , next_doc ),
@@ -351,21 +351,6 @@ fromlist is not empty. Level is used to determine whether to perform
351351absolute or relative imports. 0 is absolute while a positive number
352352is the number of parent directories to search relative to the current module.`
353353
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-
369354const ord_doc = `ord(c) -> integer
370355
371356Return the integer ordinal of a one-character string.`
@@ -375,13 +360,13 @@ func builtin_ord(self, obj py.Object) py.Object {
375360 switch x := obj .(type ) {
376361 case py.Bytes :
377362 size = len (x )
378- if len ( x ) == 1 {
363+ if size == 1 {
379364 return py .Int (x [0 ])
380365 }
381366 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 {
385370 return py .Int (rune )
386371 }
387372 //case py.ByteArray:
@@ -396,7 +381,7 @@ func builtin_ord(self, obj py.Object) py.Object {
396381 panic (py .ExceptionNewf (py .TypeError , "ord() expected string of length 1, but %s found" , obj .Type ().Name ))
397382 }
398383
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 ))
400385}
401386
402387const getattr_doc = `getattr(object, name[, default]) -> value
@@ -575,3 +560,11 @@ func builtin_chr(self py.Object, args py.Tuple) py.Object {
575560 n := utf8 .EncodeRune (buf , rune (x ))
576561 return py .String (buf [:n ])
577562}
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