You've already forked python-uncompyle6
mirror of
https://github.com/rocky/python-uncompyle6.git
synced 2025-08-02 16:44:46 +08:00
Better doc string detection
A bug in 2.7 test_descr.py revealed a problem with the way we were detecting docstrings. __doc__ = DocDescr() was getting confused with a docstring. This program also reveals other bugs in 3.2+ but we'll deal with that in another commit.
This commit is contained in:
@@ -21,7 +21,7 @@ for path in py_source:
|
||||
cfile = "bytecode_%s%s/%s" % (version, suffix, short) + "c"
|
||||
print("byte-compiling %s to %s" % (path, cfile))
|
||||
optimize = 2
|
||||
if vers >= (3, 0):
|
||||
if vers > (3, 1):
|
||||
py_compile.compile(path, cfile, optimize=optimize)
|
||||
else:
|
||||
py_compile.compile(path, cfile)
|
||||
|
BIN
test/bytecode_2.7_run/03_doc_assign.pyc
Normal file
BIN
test/bytecode_2.7_run/03_doc_assign.pyc
Normal file
Binary file not shown.
BIN
test/bytecode_3.1_run/03_doc_assign.pyc
Normal file
BIN
test/bytecode_3.1_run/03_doc_assign.pyc
Normal file
Binary file not shown.
BIN
test/bytecode_3.3_run/03_doc_assign.pyc-notyet
Normal file
BIN
test/bytecode_3.3_run/03_doc_assign.pyc-notyet
Normal file
Binary file not shown.
BIN
test/bytecode_3.6_run/03_doc_assign.pyc-notyet
Normal file
BIN
test/bytecode_3.6_run/03_doc_assign.pyc-notyet
Normal file
Binary file not shown.
27
test/simple_source/bug27+/03_doc_assign.py
Normal file
27
test/simple_source/bug27+/03_doc_assign.py
Normal file
@@ -0,0 +1,27 @@
|
||||
# From 2.7 test_descr.py
|
||||
# Testing __doc__ descriptor...
|
||||
# The bug in decompilation was erroneously matching
|
||||
# __doc__ = as a docstring
|
||||
|
||||
"""This program is self-checking!"""
|
||||
|
||||
def test_doc_descriptor():
|
||||
# Testing __doc__ descriptor...
|
||||
# Python SF bug 542984
|
||||
class DocDescr(object):
|
||||
def __get__(self, object, otype):
|
||||
if object:
|
||||
object = object.__class__.__name__ + ' instance'
|
||||
if otype:
|
||||
otype = otype.__name__
|
||||
return 'object=%s; type=%s' % (object, otype)
|
||||
class OldClass:
|
||||
__doc__ = DocDescr()
|
||||
class NewClass(object):
|
||||
__doc__ = DocDescr()
|
||||
assert OldClass.__doc__ == 'object=None; type=OldClass'
|
||||
assert OldClass().__doc__ == 'object=OldClass instance; type=OldClass'
|
||||
assert NewClass.__doc__ == 'object=None; type=NewClass'
|
||||
assert NewClass().__doc__ == 'object=NewClass instance; type=NewClass'
|
||||
|
||||
test_doc_descriptor()
|
Reference in New Issue
Block a user