未验证 提交 97794eca 编写于 作者: R Ren Wei (任卫) 提交者: GitHub

str in python2 is different to python3's, it make mistakes for some api's docstring (#32588)

* UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 1788: ordinal not in range(128)

test=document_fix

str(doc) in python2

test=document_fix

* update md5 function in count_api_without_core_ops.py

str in py2 is different.

test=document_fix
上级 a08a118d
......@@ -22,6 +22,7 @@ import pydoc
import hashlib
import six
import functools
import platform
__all__ = ['get_apis_with_and_without_core_ops', ]
......@@ -34,9 +35,20 @@ omitted_list = [
def md5(doc):
hash = hashlib.md5()
hash.update(str(doc).encode('utf-8'))
return hash.hexdigest()
try:
hashinst = hashlib.md5()
if platform.python_version()[0] == "2":
hashinst.update(str(doc))
else:
hashinst.update(str(doc).encode('utf-8'))
md5sum = hashinst.hexdigest()
except UnicodeDecodeError as e:
md5sum = None
print(
"Error({}) occurred when `md5({})`, discard it.".format(
str(e), doc),
file=sys.stderr)
return md5sum
def split_with_and_without_core_ops(member, cur_name):
......
......@@ -34,9 +34,21 @@ visited_modules = set()
def md5(doc):
hash = hashlib.md5()
hash.update(str(doc).encode('utf-8'))
return hash.hexdigest()
try:
hashinst = hashlib.md5()
if platform.python_version()[0] == "2":
hashinst.update(str(doc))
else:
hashinst.update(str(doc).encode('utf-8'))
md5sum = hashinst.hexdigest()
except UnicodeDecodeError as e:
md5sum = None
print(
"Error({}) occurred when `md5({})`, discard it.".format(
str(e), doc),
file=sys.stderr)
return md5sum
def get_functools_partial_spec(func):
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册