Last active
April 21, 2018 15:25
-
-
Save t-sin/b007cb93661d95f89fee41eee53837d7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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