Skip to content

Instantly share code, notes, and snippets.

@t-sin
Last active April 21, 2018 15:25
Show Gist options
  • Save t-sin/b007cb93661d95f89fee41eee53837d7 to your computer and use it in GitHub Desktop.
Save t-sin/b007cb93661d95f89fee41eee53837d7 to your computer and use it in GitHub Desktop.
import inspect as ins
import sys
import io
from contextlib import redirect_stdout
import re
'''
inspect.getfullargspec()で引数情報を取得できないモジュールを出力
## 気になったところ
- math.cosとかがargspecとれない…
- operator.addとかもargspecとれない…
扱いをどうすればいいか…。わりと致命的。
## 豆知識
`antigrabity`モジュールをインポートすると、ウェブページが開く
'''
def get_all_modules():
sio = io.StringIO()
with redirect_stdout(sio):
help('modules')
print('='*20)
help_modules = sio.getvalue().splitlines()
modules = []
is_modline = False
# importするとおつるモジュール
_blacklist = [
'turtle',
'tkinter',
]
for line in help_modules:
if re.match('^Please wait', line):
is_modline = True
continue
if re.match('^Enter any module', line):
is_modline = False
if is_modline and len(line) != 0:
modules = modules + [s for s in line.split(' ') if len(s) > 0 and not re.match('^_', s) and s not in _blacklist]
modules.sort()
return modules
def print_errorargspec(m):
builtins = [(n, o) for n, o in ins.getmembers(__import__(m)) if ins.isbuiltin(o)]
error_getargspec = []
for n, o in builtins:
try:
ins.getfullargspec(o)
# print(n, ': ', ins.getfullargspec(o))
except Exception as e:
error_getargspec.append(n)
continue
# argspecとれなかったモジュールを出力
if len(error_getargspec) > 0:
print('<module {}>'.format(m), ':', error_getargspec)
for m in get_all_modules(): print_errorargspec(m)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment