From 3f2f3ab08c551a21d3c9013b316d14e44ace0380 Mon Sep 17 00:00:00 2001 From: Alan Justino Date: Thu, 27 Apr 2017 19:15:41 -0300 Subject: [PATCH 01/16] PEP-8 Nazi (should I follow the Google 2-space or PEP 4-space?) --- lib/sys.py | 49 +++++++++++++++++++++++++------------------------ 1 file changed, 25 insertions(+), 24 deletions(-) diff --git a/lib/sys.py b/lib/sys.py index 7d98c488..ecd4f7fb 100644 --- a/lib/sys.py +++ b/lib/sys.py @@ -21,7 +21,7 @@ argv = [] for arg in Args: - argv.append(arg) + argv.append(arg) goversion = Version() maxint = MaxInt @@ -34,35 +34,36 @@ byteorder = 'little' class _Flags(object): - """Container class for sys.flags.""" - debug = 0 - py3k_warning = 0 - division_warning = 0 - division_new = 0 - inspect = 0 - interactive = 0 - optimize = 0 - dont_write_bytecode = 0 - no_user_site = 0 - no_site = 0 - ignore_environment = 0 - tabcheck = 0 - verbose = 0 - unicode = 0 - bytes_warning = 0 - hash_randomization = 0 + """Container class for sys.flags.""" + debug = 0 + py3k_warning = 0 + division_warning = 0 + division_new = 0 + inspect = 0 + interactive = 0 + optimize = 0 + dont_write_bytecode = 0 + no_user_site = 0 + no_site = 0 + ignore_environment = 0 + tabcheck = 0 + verbose = 0 + unicode = 0 + bytes_warning = 0 + hash_randomization = 0 flags = _Flags() def exc_info(): - e, tb = __frame__().__exc_info__() # pylint: disable=undefined-variable - t = None - if e: - t = type(e) - return t, e, tb + e, tb = __frame__().__exc_info__() # pylint: disable=undefined-variable + t = None + if e: + t = type(e) + return t, e, tb def exit(code=None): # pylint: disable=redefined-builtin - raise SystemExit(code) + raise SystemExit(code) + From a02c0169bef0032345ae160a6481d576124fcd8b Mon Sep 17 00:00:00 2001 From: Alan Justino Date: Fri, 28 Apr 2017 12:30:21 -0300 Subject: [PATCH 02/16] [WIP] Hybrid sysmodule.go+sys.py Needs working __getattr__/__setattr__. Please wait if before merge --- lib/sys.py | 31 ++++++++++++++++++++++++++++++- runtime/sysmodule.go | 26 ++++++++++++++++++++++++++ testing/sysmodule_test.py | 15 +++++++++++++++ 3 files changed, 71 insertions(+), 1 deletion(-) create mode 100644 runtime/sysmodule.go create mode 100644 testing/sysmodule_test.py diff --git a/lib/sys.py b/lib/sys.py index ecd4f7fb..0d93e7b4 100644 --- a/lib/sys.py +++ b/lib/sys.py @@ -15,24 +15,37 @@ """System-specific parameters and functions.""" from __go__.os import Args -from __go__.grumpy import SysModules, MaxInt, Stdin as stdin, Stdout as stdout, Stderr as stderr # pylint: disable=g-multiple-import +from __go__.grumpy import SysmoduleDict, SysModules, MaxInt, Stdin, Stdout, Stderr # pylint: disable=g-multiple-import from __go__.runtime import Version from __go__.unicode import MaxRune + +__all__ = ('stdin', 'stdout', 'stderr', 'argv', '_goversion', + 'maxint', 'maxsize', 'maxunicode', 'modules', 'py3kwarning', + 'warnoptions', 'byteorder', 'flags', 'exc_info', 'exit') + + argv = [] for arg in Args: argv.append(arg) goversion = Version() + +stdin = SysmoduleDict['stdin'] +stdout = SysmoduleDict['stdout'] +stderr = SysmoduleDict['stderr'] + maxint = MaxInt maxsize = maxint maxunicode = MaxRune modules = SysModules + py3kwarning = False warnoptions = [] # TODO: Support actual byteorder byteorder = 'little' + class _Flags(object): """Container class for sys.flags.""" debug = 0 @@ -67,3 +80,19 @@ def exc_info(): def exit(code=None): # pylint: disable=redefined-builtin raise SystemExit(code) + +# TODO: Clear this HACK: Should be the last lines of the python part of hybrid stuff +class _SysModule(object): + def __init__(self): + for k in ('__name__', '__file__') + __all__: + SysmoduleDict[k] = globals()[k] + def __setattr__(self, name, value): + SysmoduleDict[name] = value + def __getattr__(self, name): + resp = SysmoduleDict.get(name) + if res is None and name not in SysmoduleDict: + return super(_SysModule, self).__getattr__(name) + return resp + +modules = SysModules +modules['sys'] = _SysModule() diff --git a/runtime/sysmodule.go b/runtime/sysmodule.go new file mode 100644 index 00000000..c0b15777 --- /dev/null +++ b/runtime/sysmodule.go @@ -0,0 +1,26 @@ +// Copyright 2016 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package grumpy + +var ( + // Sysmodule is the __dict__ of the native part of sys.py. + SysmoduleDict = newStringDict(map[string]*Object{ + "__file__": NewStr("").ToObject(), + "__name__": NewStr("_sys").ToObject(), + "stdin": Stdin.ToObject(), + "stdout": Stdout.ToObject(), + "stderr": Stderr.ToObject(), + }) +) diff --git a/testing/sysmodule_test.py b/testing/sysmodule_test.py new file mode 100644 index 00000000..6d4bc3a1 --- /dev/null +++ b/testing/sysmodule_test.py @@ -0,0 +1,15 @@ +from StringIO import StringIO +import sys + +print 'To sys.stdout' + +old_stdout = sys.stdout +sio = StringIO() +sys.stdout = sio + +print 'To replaced sys.stdout' + +sys.stdout = old_stdout +print 'To original sys.stdout' + +assert sio.tell() == len('To replaced sys.stdout')+1, 'Should had printed to StringIO, not STDOUT' \ No newline at end of file From 89546c2172481d49e9aa236846cad895ff060743 Mon Sep 17 00:00:00 2001 From: Alan Justino Date: Fri, 28 Apr 2017 12:40:07 -0300 Subject: [PATCH 03/16] docs. --- runtime/sysmodule.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runtime/sysmodule.go b/runtime/sysmodule.go index c0b15777..9dc2eaf9 100644 --- a/runtime/sysmodule.go +++ b/runtime/sysmodule.go @@ -15,7 +15,7 @@ package grumpy var ( - // Sysmodule is the __dict__ of the native part of sys.py. + // SysmoduleDict is the __dict__ of the native part of sys.py. SysmoduleDict = newStringDict(map[string]*Object{ "__file__": NewStr("").ToObject(), "__name__": NewStr("_sys").ToObject(), From f8ea5e5a4521fe6a1c2eccbf8d37e2262be60dcc Mon Sep 17 00:00:00 2001 From: Alan Justino Date: Sat, 29 Apr 2017 17:49:37 -0300 Subject: [PATCH 04/16] Use __getattribute__ instead of __getattr__ --- lib/sys.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/sys.py b/lib/sys.py index 0d93e7b4..9e09c1e9 100644 --- a/lib/sys.py +++ b/lib/sys.py @@ -88,10 +88,10 @@ def __init__(self): SysmoduleDict[k] = globals()[k] def __setattr__(self, name, value): SysmoduleDict[name] = value - def __getattr__(self, name): + def __getattribute__(self, name): # TODO: replace w/ __getattr__ when implemented resp = SysmoduleDict.get(name) if res is None and name not in SysmoduleDict: - return super(_SysModule, self).__getattr__(name) + return super(_SysModule, self).__getattribute__(name) return resp modules = SysModules From c09c642ed2fc2430e01b036dc24274d2b0640bde Mon Sep 17 00:00:00 2001 From: Alan Justino Date: Sun, 30 Apr 2017 23:31:24 -0300 Subject: [PATCH 05/16] Typos --- lib/sys.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/sys.py b/lib/sys.py index 9e09c1e9..c0cee4df 100644 --- a/lib/sys.py +++ b/lib/sys.py @@ -20,7 +20,7 @@ from __go__.unicode import MaxRune -__all__ = ('stdin', 'stdout', 'stderr', 'argv', '_goversion', +__all__ = ('stdin', 'stdout', 'stderr', 'argv', 'goversion', 'maxint', 'maxsize', 'maxunicode', 'modules', 'py3kwarning', 'warnoptions', 'byteorder', 'flags', 'exc_info', 'exit') @@ -90,7 +90,7 @@ def __setattr__(self, name, value): SysmoduleDict[name] = value def __getattribute__(self, name): # TODO: replace w/ __getattr__ when implemented resp = SysmoduleDict.get(name) - if res is None and name not in SysmoduleDict: + if resp is None and name not in SysmoduleDict: return super(_SysModule, self).__getattribute__(name) return resp From b35a243b357dd3c338097036449fe27cedca5eec Mon Sep 17 00:00:00 2001 From: Alan Justino Date: Mon, 1 May 2017 01:13:34 -0300 Subject: [PATCH 06/16] pyPrint prints to any filelike having .write() --- runtime/builtin_types.go | 4 ++-- runtime/core.go | 37 +++++++++++++++++++++++-------------- 2 files changed, 25 insertions(+), 16 deletions(-) diff --git a/runtime/builtin_types.go b/runtime/builtin_types.go index d19d2045..5a176b66 100644 --- a/runtime/builtin_types.go +++ b/runtime/builtin_types.go @@ -562,7 +562,7 @@ func builtinPrint(f *Frame, args Args, kwargs KWArgs) (*Object, *BaseException) // to the file descriptor probably } } - return nil, pyPrint(f, args, sep, end, file) + return nil, pyPrint(f, args, sep, end, file.ToObject()) } func builtinRange(f *Frame, args Args, kwargs KWArgs) (*Object, *BaseException) { @@ -590,7 +590,7 @@ func builtinRawInput(f *Frame, args Args, kwargs KWArgs) (*Object, *BaseExceptio } if len(args) == 1 { - err := pyPrint(f, args, "", "", Stdout) + err := pyPrint(f, args, "", "", Stdout.ToObject()) if err != nil { return nil, err } diff --git a/runtime/core.go b/runtime/core.go index 966a2dc9..35c7e205 100644 --- a/runtime/core.go +++ b/runtime/core.go @@ -683,7 +683,7 @@ func Print(f *Frame, args Args, nl bool) *BaseException { } else if len(args) > 0 { end = " " } - return pyPrint(f, args, " ", end, Stdout) + return pyPrint(f, args, " ", end, Stdout.ToObject()) } // Repr returns a string containing a printable representation of o. This is @@ -1258,29 +1258,38 @@ func hashNotImplemented(f *Frame, o *Object) (*Object, *BaseException) { } // pyPrint encapsulates the logic of the Python print function. -func pyPrint(f *Frame, args Args, sep, end string, file *File) *BaseException { +func pyPrint(f *Frame, args Args, sep, end string, filelike *Object) *BaseException { + writeFunc, raised := GetAttr(f, filelike, NewStr("write"), nil) + if raised != nil { + return raised + } + + pySep := NewStr(sep) + pyEnd := NewStr(end) + callArgs := f.MakeArgs(1) for i, arg := range args { if i > 0 { - err := file.writeString(sep) - if err != nil { - return f.RaiseType(IOErrorType, err.Error()) + callArgs[0] = pySep.ToObject() + _, raised := writeFunc.Call(f, callArgs, nil) + if raised != nil { + return raised } } - s, raised := ToStr(f, arg) - if raised != nil { - return raised + s, raised_ := ToStr(f, arg) + if raised_ != nil { + return raised_ } - err := file.writeString(s.Value()) - if err != nil { - return f.RaiseType(IOErrorType, err.Error()) + callArgs[0] = s.ToObject() + if _, raised := writeFunc.Call(f, callArgs, nil); raised != nil { + return raised } } - err := file.writeString(end) - if err != nil { - return f.RaiseType(IOErrorType, err.Error()) + callArgs[0] = pyEnd.ToObject() + if _, raised := writeFunc.Call(f, callArgs, nil); raised != nil { + return raised } return nil From c4bfdf48af2a9022143fad2038f23d15ba686744 Mon Sep 17 00:00:00 2001 From: Alan Justino Date: Mon, 1 May 2017 15:57:12 -0300 Subject: [PATCH 07/16] print to sys.stdout, not Stdout --- runtime/core.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/runtime/core.go b/runtime/core.go index 35c7e205..9a76e5eb 100644 --- a/runtime/core.go +++ b/runtime/core.go @@ -683,7 +683,11 @@ func Print(f *Frame, args Args, nl bool) *BaseException { } else if len(args) > 0 { end = " " } - return pyPrint(f, args, " ", end, Stdout.ToObject()) + file, raised := SysmoduleDict.GetItemString(f, "stdout") + if raised != nil { + return raised + } + return pyPrint(f, args, " ", end, file) } // Repr returns a string containing a printable representation of o. This is From 66f52c00eff83868e0e7632e36fa2b0e1d56c329 Mon Sep 17 00:00:00 2001 From: Alan Justino Date: Sat, 10 Jun 2017 15:29:09 -0300 Subject: [PATCH 08/16] sys.platform is back Conflicts: lib/sys.py --- lib/sys.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/sys.py b/lib/sys.py index c0cee4df..5fd7e50a 100644 --- a/lib/sys.py +++ b/lib/sys.py @@ -15,13 +15,13 @@ """System-specific parameters and functions.""" from __go__.os import Args -from __go__.grumpy import SysmoduleDict, SysModules, MaxInt, Stdin, Stdout, Stderr # pylint: disable=g-multiple-import +from __go__.grumpy import SysmoduleDict, SysModules, MaxInt # pylint: disable=g-multiple-import from __go__.runtime import Version from __go__.unicode import MaxRune __all__ = ('stdin', 'stdout', 'stderr', 'argv', 'goversion', - 'maxint', 'maxsize', 'maxunicode', 'modules', 'py3kwarning', + 'maxint', 'maxsize', 'maxunicode', 'modules', 'platform', 'py3kwarning', 'warnoptions', 'byteorder', 'flags', 'exc_info', 'exit') From 96c75688652a0c54aa8d74cf45d605f221b2c03e Mon Sep 17 00:00:00 2001 From: Alan Justino Date: Sat, 10 Jun 2017 15:29:30 -0300 Subject: [PATCH 09/16] Segregate HybridModule hack to its own module --- lib/_gomodulehacks.py | 31 +++++++++++++++++++++++++++++++ lib/sys.py | 18 +++--------------- 2 files changed, 34 insertions(+), 15 deletions(-) create mode 100644 lib/_gomodulehacks.py diff --git a/lib/_gomodulehacks.py b/lib/_gomodulehacks.py new file mode 100644 index 00000000..d213527a --- /dev/null +++ b/lib/_gomodulehacks.py @@ -0,0 +1,31 @@ +# coding: utf-8 + +from __go__.grumpy import SysModules + + +def hybrid_module(modulename, modulefile, moduledict, all_attrs, globals_): + """ + Augment native 'moduledict' with Python-sourced parts + + Allows 'modulename' to use 'moduledict' from outside, + for example a Grumpy dict from native module. + + And does include the resulting module on sys.modules at the end. + """ + class HybridModule(object): + def __init__(self): + moduledict['__name__'] = modulename + moduledict['__file__'] = modulefile + for k in all_attrs: + moduledict[k] = globals_[k] + def __setattr__(self, name, value): + moduledict[name] = value + def __getattribute__(self, name): # TODO: replace w/ __getattr__ when implemented + resp = moduledict.get(name) + if resp is None and name not in moduledict: + return super(HybridModule, self).__getattribute__(name) + return resp + + finalmodule = HybridModule() + SysModules[modulename] = finalmodule + return finalmodule diff --git a/lib/sys.py b/lib/sys.py index 5fd7e50a..0da419c0 100644 --- a/lib/sys.py +++ b/lib/sys.py @@ -18,6 +18,7 @@ from __go__.grumpy import SysmoduleDict, SysModules, MaxInt # pylint: disable=g-multiple-import from __go__.runtime import Version from __go__.unicode import MaxRune +import _gomodulehacks __all__ = ('stdin', 'stdout', 'stderr', 'argv', 'goversion', @@ -81,18 +82,5 @@ def exit(code=None): # pylint: disable=redefined-builtin raise SystemExit(code) -# TODO: Clear this HACK: Should be the last lines of the python part of hybrid stuff -class _SysModule(object): - def __init__(self): - for k in ('__name__', '__file__') + __all__: - SysmoduleDict[k] = globals()[k] - def __setattr__(self, name, value): - SysmoduleDict[name] = value - def __getattribute__(self, name): # TODO: replace w/ __getattr__ when implemented - resp = SysmoduleDict.get(name) - if resp is None and name not in SysmoduleDict: - return super(_SysModule, self).__getattribute__(name) - return resp - -modules = SysModules -modules['sys'] = _SysModule() +# Should be the last line of the python part of hybrid stuff +_gomodulehacks.hybrid_module(__name__, __file__, SysmoduleDict, __all__, globals()) From f745cdb8bcda8c97be38eb699bea36e6993dd46d Mon Sep 17 00:00:00 2001 From: Alan Justino Date: Sat, 10 Jun 2017 16:16:02 -0300 Subject: [PATCH 10/16] HybridModule is a Module subclass --- lib/_gomodulehacks.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/_gomodulehacks.py b/lib/_gomodulehacks.py index d213527a..84b7a071 100644 --- a/lib/_gomodulehacks.py +++ b/lib/_gomodulehacks.py @@ -1,6 +1,10 @@ # coding: utf-8 from __go__.grumpy import SysModules +import errno + +# For some reason, importing and extending grumpy.Module does not work. +Module = type(errno) def hybrid_module(modulename, modulefile, moduledict, all_attrs, globals_): @@ -12,7 +16,7 @@ def hybrid_module(modulename, modulefile, moduledict, all_attrs, globals_): And does include the resulting module on sys.modules at the end. """ - class HybridModule(object): + class HybridModule(Module): def __init__(self): moduledict['__name__'] = modulename moduledict['__file__'] = modulefile From 7c1cfdee7e1f80b23355fa7d6332eec273c4ed15 Mon Sep 17 00:00:00 2001 From: Alan Justino Date: Sat, 10 Jun 2017 16:16:19 -0300 Subject: [PATCH 11/16] Docs on intended call of hybrid_module --- lib/_gomodulehacks.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/_gomodulehacks.py b/lib/_gomodulehacks.py index 84b7a071..3412e485 100644 --- a/lib/_gomodulehacks.py +++ b/lib/_gomodulehacks.py @@ -15,6 +15,10 @@ def hybrid_module(modulename, modulefile, moduledict, all_attrs, globals_): for example a Grumpy dict from native module. And does include the resulting module on sys.modules at the end. + + Should be called as: + hybrid_module(__name__, __file__, YourmoduleDict, __all__, globals()) + On the last line of the Python-part of the module """ class HybridModule(Module): def __init__(self): From 59a8436c77b7a842e7c6d161dd252f8e614c7b1c Mon Sep 17 00:00:00 2001 From: Alan Justino Date: Sat, 10 Jun 2017 16:36:53 -0300 Subject: [PATCH 12/16] gofmt --- runtime/core.go | 2 +- runtime/sysmodule.go | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/runtime/core.go b/runtime/core.go index 9a76e5eb..4e7558ab 100644 --- a/runtime/core.go +++ b/runtime/core.go @@ -1292,7 +1292,7 @@ func pyPrint(f *Frame, args Args, sep, end string, filelike *Object) *BaseExcept } callArgs[0] = pyEnd.ToObject() - if _, raised := writeFunc.Call(f, callArgs, nil); raised != nil { + if _, raised := writeFunc.Call(f, callArgs, nil); raised != nil { return raised } diff --git a/runtime/sysmodule.go b/runtime/sysmodule.go index 9dc2eaf9..a3622336 100644 --- a/runtime/sysmodule.go +++ b/runtime/sysmodule.go @@ -19,8 +19,8 @@ var ( SysmoduleDict = newStringDict(map[string]*Object{ "__file__": NewStr("").ToObject(), "__name__": NewStr("_sys").ToObject(), - "stdin": Stdin.ToObject(), - "stdout": Stdout.ToObject(), - "stderr": Stderr.ToObject(), + "stdin": Stdin.ToObject(), + "stdout": Stdout.ToObject(), + "stderr": Stderr.ToObject(), }) ) From 2390e5bfde5df20a8e1e1aba4da6c1c1aaee098f Mon Sep 17 00:00:00 2001 From: Alan Justino Date: Sat, 10 Jun 2017 16:48:15 -0300 Subject: [PATCH 13/16] golint --- runtime/core.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/runtime/core.go b/runtime/core.go index 4e7558ab..0abdb9ce 100644 --- a/runtime/core.go +++ b/runtime/core.go @@ -1280,9 +1280,9 @@ func pyPrint(f *Frame, args Args, sep, end string, filelike *Object) *BaseExcept } } - s, raised_ := ToStr(f, arg) - if raised_ != nil { - return raised_ + s, raised2 := ToStr(f, arg) + if raised2 != nil { + return raised2 } callArgs[0] = s.ToObject() From 23eaabecbfc02d2fc95338e340bf3277ce233c66 Mon Sep 17 00:00:00 2001 From: Alan Justino Date: Sat, 10 Jun 2017 17:45:06 -0300 Subject: [PATCH 14/16] sys.{version,exc_clear} --- lib/sys.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/sys.py b/lib/sys.py index 45bcb299..5b79a6c6 100644 --- a/lib/sys.py +++ b/lib/sys.py @@ -21,9 +21,9 @@ import _gomodulehacks -__all__ = ('stdin', 'stdout', 'stderr', 'argv', 'goversion', +__all__ = ('stdin', 'stdout', 'stderr', 'argv', 'goversion', 'version', 'maxint', 'maxsize', 'maxunicode', 'modules', 'platform', 'py3kwarning', - 'warnoptions', 'byteorder', 'flags', 'exc_info', 'exit') + 'warnoptions', 'byteorder', 'flags', 'exc_clear', 'exc_info', 'exit') argv = [] From fca272a606178fa716053c637aeb4c98f6ec48b8 Mon Sep 17 00:00:00 2001 From: Alan Justino Date: Tue, 13 Jun 2017 01:39:43 -0300 Subject: [PATCH 15/16] Oops: Forgot one Stdout.ToObject() --- runtime/core_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runtime/core_test.go b/runtime/core_test.go index d41b682b..e48df14f 100644 --- a/runtime/core_test.go +++ b/runtime/core_test.go @@ -818,7 +818,7 @@ func TestPos(t *testing.T) { func TestPyPrint(t *testing.T) { fun := wrapFuncForTest(func(f *Frame, args *Tuple, sep, end string) (string, *BaseException) { return captureStdout(f, func() *BaseException { - return pyPrint(NewRootFrame(), args.elems, sep, end, Stdout) + return pyPrint(NewRootFrame(), args.elems, sep, end, Stdout.ToObject()) }) }) cases := []invokeTestCase{ From 35fc2a3511b182375f734e315218820774f8b9ce Mon Sep 17 00:00:00 2001 From: Alan Justino Date: Fri, 16 Jun 2017 14:07:41 -0300 Subject: [PATCH 16/16] "sys" module is special. Use "errno" to get ModuleType --- third_party/stdlib/types.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/third_party/stdlib/types.py b/third_party/stdlib/types.py index 65e1fb62..fe55eed3 100644 --- a/third_party/stdlib/types.py +++ b/third_party/stdlib/types.py @@ -3,6 +3,7 @@ Types that are part of optional modules (e.g. array) are not listed. """ import sys +import errno # Iterators in Python aren't a matter of type but of protocol. A large # and changing number of builtin types implement *some* flavor of @@ -59,7 +60,7 @@ def _m(self): pass BuiltinFunctionType = type(len) BuiltinMethodType = type([].append) # Same as BuiltinFunctionType -ModuleType = type(sys) +ModuleType = type(errno) FileType = file XRangeType = xrange