Remove PYTHON3

This commit is contained in:
rocky 2021-11-03 03:00:43 -04:00
parent f6f0e344d0
commit 8094f3bb12
9 changed files with 47 additions and 109 deletions

View File

@ -1,7 +1,7 @@
import re import re
from uncompyle6.parser import get_python_parser, python_parser from uncompyle6.parser import get_python_parser, python_parser
from uncompyle6.scanner import get_scanner from uncompyle6.scanner import get_scanner
from xdis.version_info import PYTHON_VERSION_TRIPLE, PYTHON3, IS_PYPY from xdis.version_info import PYTHON_VERSION_TRIPLE, IS_PYPY
def test_grammar(): def test_grammar():
@ -50,34 +50,29 @@ def test_grammar():
# NOTE: this may disappear # NOTE: this may disappear
expect_lhs.add("except_handler_else") expect_lhs.add("except_handler_else")
if PYTHON3: expect_lhs.add("load_genexpr")
expect_lhs.add("load_genexpr")
unused_rhs = unused_rhs.union( unused_rhs = unused_rhs.union(
set( set(
""" """
except_pop_except generator_exp except_pop_except generator_exp
""".split() """.split()
)
) )
if PYTHON_VERSION_TRIPLE >= (3, 0): )
if PYTHON_VERSION_TRIPLE < (3, 7): if PYTHON_VERSION_TRIPLE < (3, 7):
expect_lhs.add("annotate_arg") expect_lhs.add("annotate_arg")
expect_lhs.add("annotate_tuple") expect_lhs.add("annotate_tuple")
unused_rhs.add("mkfunc_annotate") unused_rhs.add("mkfunc_annotate")
unused_rhs.add("dict_comp") unused_rhs.add("dict_comp")
unused_rhs.add("classdefdeco1") unused_rhs.add("classdefdeco1")
unused_rhs.add("tryelsestmtl") unused_rhs.add("tryelsestmtl")
if PYTHON_VERSION_TRIPLE >= (3, 5): if PYTHON_VERSION_TRIPLE >= (3, 5):
expect_right_recursive.add( expect_right_recursive.add(
(("l_stmts", ("lastl_stmt", "come_froms", "l_stmts"))) (("l_stmts", ("lastl_stmt", "come_froms", "l_stmts")))
) )
pass
pass
pass pass
else: pass
expect_lhs.add("kwarg")
# FIXME # FIXME
if PYTHON_VERSION_TRIPLE < (3, 8): if PYTHON_VERSION_TRIPLE < (3, 8):

View File

@ -10,7 +10,7 @@ import functools
# uncompyle6 / xdis # uncompyle6 / xdis
from uncompyle6 import code_deparse from uncompyle6 import code_deparse
from xdis.version_info import PYTHON_VERSION_TRIPLE, PYTHON3, IS_PYPY from xdis.version_info import PYTHON_VERSION_TRIPLE, IS_PYPY
# TODO : I think we can get xdis to support the dis api (python 3 version) by doing something like this there # TODO : I think we can get xdis to support the dis api (python 3 version) by doing something like this there
from xdis import Bytecode, get_opcode from xdis import Bytecode, get_opcode
@ -19,12 +19,6 @@ opc = get_opcode(PYTHON_VERSION_TRIPLE, IS_PYPY)
Bytecode = functools.partial(Bytecode, opc=opc) Bytecode = functools.partial(Bytecode, opc=opc)
import six import six
if PYTHON3:
from io import StringIO
else:
from StringIO import StringIO
def _dis_to_text(co): def _dis_to_text(co):
return Bytecode(co).dis() return Bytecode(co).dis()

View File

@ -25,7 +25,7 @@ from __future__ import print_function
import os, time, re, shutil, sys import os, time, re, shutil, sys
from fnmatch import fnmatch from fnmatch import fnmatch
from uncompyle6 import main, PYTHON3 from uncompyle6 import main
import xdis.magics as magics import xdis.magics as magics
# ----- configure this for your needs # ----- configure this for your needs
@ -111,20 +111,16 @@ def do_tests(
files = [] files = []
cwd = os.getcwd() cwd = os.getcwd()
os.chdir(src_dir) os.chdir(src_dir)
if PYTHON3: for root, dirname, names in os.walk(os.curdir):
for root, dirname, names in os.walk(os.curdir): files.extend(
files.extend( [
[ os.path.normpath(os.path.join(root, n))
os.path.normpath(os.path.join(root, n)) for n in names
for n in names for pat in patterns
for pat in patterns if fnmatch(n, pat)
if fnmatch(n, pat) ]
] )
)
pass
pass pass
else:
os.path.walk(os.curdir, visitor, files)
os.chdir(cwd) os.chdir(cwd)
files.sort() files.sort()

View File

@ -43,7 +43,6 @@ from uncompyle6.parsers.reducecheck import (
) )
from uncompyle6.parsers.treenode import SyntaxTree from uncompyle6.parsers.treenode import SyntaxTree
from spark_parser import DEFAULT_DEBUG as PARSER_DEFAULT_DEBUG from spark_parser import DEFAULT_DEBUG as PARSER_DEFAULT_DEBUG
from xdis import PYTHON3
class Python3Parser(PythonParser): class Python3Parser(PythonParser):
@ -626,10 +625,7 @@ class Python3Parser(PythonParser):
this has an effect on many rules. this has an effect on many rules.
""" """
if self.version >= (3, 3): if self.version >= (3, 3):
if PYTHON3 or not self.is_pypy: load_op = "LOAD_STR "
load_op = "LOAD_STR "
else:
load_op = "LOAD_CONST "
new_rule = rule % ((load_op) * 1) new_rule = rule % ((load_op) * 1)
else: else:
@ -1157,7 +1153,7 @@ class Python3Parser(PythonParser):
) )
elif self.version >= (3, 4): elif self.version >= (3, 4):
if PYTHON3 or not self.is_pypy: if not self.is_pypy:
load_op = "LOAD_STR" load_op = "LOAD_STR"
else: else:
load_op = "LOAD_CONST" load_op = "LOAD_CONST"
@ -1235,14 +1231,6 @@ class Python3Parser(PythonParser):
opname, opname,
) )
self.add_unique_rule(rule, opname, token.attr, customize) self.add_unique_rule(rule, opname, token.attr, customize)
if not PYTHON3 and self.is_pypy:
rule = "mkfunc ::= %s%s%s%s" % (
"expr " * stack_count,
"load_closure " * closure,
"LOAD_CODE LOAD_CONST ",
opname,
)
self.add_unique_rule(rule, opname, token.attr, customize)
if has_get_iter_call_function1: if has_get_iter_call_function1:
rule_pat = ( rule_pat = (
@ -1566,8 +1554,6 @@ class Python3Parser(PythonParser):
self.check_reduce["iflaststmtl"] = "AST" self.check_reduce["iflaststmtl"] = "AST"
self.check_reduce["or"] = "AST" self.check_reduce["or"] = "AST"
self.check_reduce["testtrue"] = "tokens" self.check_reduce["testtrue"] = "tokens"
if not PYTHON3:
self.check_reduce["kwarg"] = "noAST"
if self.version < (3, 6) and not self.is_pypy: if self.version < (3, 6) and not self.is_pypy:
# 3.6+ can remove a JUMP_FORWARD which messes up our testing here # 3.6+ can remove a JUMP_FORWARD which messes up our testing here
# Pypy we need to go over in better detail # Pypy we need to go over in better detail

View File

@ -1,10 +1,8 @@
import sys import sys
from xdis.version_info import PYTHON3
from uncompyle6.scanners.tok import NoneToken from uncompyle6.scanners.tok import NoneToken
from spark_parser.ast import AST as spark_AST from spark_parser.ast import AST as spark_AST
if PYTHON3: intern = sys.intern
intern = sys.intern
class SyntaxTree(spark_AST): class SyntaxTree(spark_AST):

View File

@ -26,7 +26,7 @@ from collections import namedtuple
import sys import sys
from uncompyle6.scanners.tok import Token from uncompyle6.scanners.tok import Token
from xdis.version_info import IS_PYPY, PYTHON3, version_tuple_to_str from xdis.version_info import IS_PYPY, version_tuple_to_str
import xdis import xdis
from xdis import ( from xdis import (
Bytecode, Bytecode,
@ -77,16 +77,11 @@ CANONIC2VERSION["3.5.2"] = 3.5
# FIXME: DRY # FIXME: DRY
if PYTHON3: intern = sys.intern
intern = sys.intern L65536 = 65536
L65536 = 65536
def long(num): def long(num):
return num return num
else:
L65536 = long(65536) # NOQA
class Code(object): class Code(object):

View File

@ -9,12 +9,10 @@ grammar parsing.
from uncompyle6.scanners.scanner2 import Scanner2 from uncompyle6.scanners.scanner2 import Scanner2
from xdis.version_info import PYTHON3, version_tuple_to_str from xdis.version_info import version_tuple_to_str
import sys
if PYTHON3: intern = sys.intern
import sys
intern = sys.intern
# bytecode verification, verify(), uses JUMP_OPs from here # bytecode verification, verify(), uses JUMP_OPs from here
from xdis.opcodes import opcode_27 from xdis.opcodes import opcode_27

View File

@ -212,10 +212,7 @@ def strip_quotes(s):
# if __name__ == '__main__': # if __name__ == '__main__':
# if PYTHON3: # from io import StringIO
# from io import StringIO
# else:
# from StringIO import StringIO
# class PrintFake(): # class PrintFake():
# def __init__(self): # def __init__(self):
# self.pending_newlines = 0 # self.pending_newlines = 0

View File

@ -133,7 +133,6 @@ Python.
import sys import sys
IS_PYPY = "__pypy__" in sys.builtin_module_names IS_PYPY = "__pypy__" in sys.builtin_module_names
PYTHON3 = sys.version_info >= (3, 0)
from xdis import iscode, COMPILER_FLAG_BIT from xdis import iscode, COMPILER_FLAG_BIT
from xdis.version_info import PYTHON_VERSION_TRIPLE from xdis.version_info import PYTHON_VERSION_TRIPLE
@ -184,11 +183,8 @@ from uncompyle6.show import maybe_show_tree
from uncompyle6.util import better_repr from uncompyle6.util import better_repr
if PYTHON3: def unicode(x): return x
def unicode(x): return x from io import StringIO
from io import StringIO
else:
from StringIO import StringIO
class SourceWalkerError(Exception): class SourceWalkerError(Exception):
@ -437,10 +433,7 @@ class SourceWalker(GenericASTTraversal, object):
def write(self, *data): def write(self, *data):
if (len(data) == 0) or (len(data) == 1 and data[0] == ""): if (len(data) == 0) or (len(data) == 1 and data[0] == ""):
return return
if not PYTHON3: out = "".join((str(j) for j in data))
out = "".join((unicode(j) for j in data))
else:
out = "".join((str(j) for j in data))
n = 0 n = 0
for i in out: for i in out:
if i == "\n": if i == "\n":
@ -467,8 +460,6 @@ class SourceWalker(GenericASTTraversal, object):
if self.pending_newlines: if self.pending_newlines:
out = out[: -self.pending_newlines] out = out[: -self.pending_newlines]
if isinstance(out, str) and not (PYTHON3 or self.FUTURE_UNICODE_LITERALS):
out = unicode(out, "utf-8")
self.f.write(out) self.f.write(out)
def println(self, *data): def println(self, *data):
@ -684,23 +675,11 @@ class SourceWalker(GenericASTTraversal, object):
# strings are interpreted: # strings are interpreted:
# u'xxx' -> 'xxx' # u'xxx' -> 'xxx'
# xxx' -> b'xxx' # xxx' -> b'xxx'
if not PYTHON3 and isinstance(data, unicode): if isinstance(data, str):
try:
data = str(data)
except UnicodeEncodeError:
# Have to keep data as it is: in Unicode.
pass
self.write(repr(data))
elif isinstance(data, str):
self.write("b" + repr(data)) self.write("b" + repr(data))
else: else:
self.write(repr(data)) self.write(repr(data))
else: else:
if not PYTHON3:
try:
repr(data).encode("ascii")
except UnicodeEncodeError:
self.write("u")
self.write(repr(data)) self.write(repr(data))
# LOAD_CONST is a terminal, so stop processing/recursing early # LOAD_CONST is a terminal, so stop processing/recursing early
self.prune() self.prune()