Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
M
my2to3
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Emmy Vouriot
my2to3
Commits
f730910d
Commit
f730910d
authored
Jul 01, 2020
by
Bryton Lacquement
🚪
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
New naming convention for fixers
parent
d92b99eb
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
19 additions
and
19 deletions
+19
-19
my2to3/fixes/__init__.py
my2to3/fixes/__init__.py
+11
-0
my2to3/fixes/fix_division_support.py
my2to3/fixes/fix_division_support.py
+4
-3
my2to3/fixes/fix_division_trace.py
my2to3/fixes/fix_division_trace.py
+3
-3
my2to3/tests/testFixDivisionTrace.py
my2to3/tests/testFixDivisionTrace.py
+1
-1
my2to3/util.py
my2to3/util.py
+0
-12
No files found.
my2to3/fixes/__init__.py
View file @
f730910d
import
lib2to3.fixer_base
import
os
class
BaseFix
(
lib2to3
.
fixer_base
.
BaseFix
):
def
start_tree
(
self
,
tree
,
filename
):
sep
=
'-'
*
5
# Arbitrary
if
sep
in
filename
:
filename
=
filename
.
split
(
sep
,
1
)[
1
].
replace
(
sep
,
os
.
sep
)
super
(
BaseFix
,
self
).
start_tree
(
tree
,
filename
)
my2to3/fixes/fix_division.py
→
my2to3/fixes/fix_division
_support
.py
View file @
f730910d
...
...
@@ -6,7 +6,8 @@ from lib2to3.pytree import Leaf, Node
import
os
import
re
from
my2to3.util
import
add_future
,
BaseFix
from
my2to3.util
import
add_future
from
my2to3.fixes
import
BaseFix
trace_file_match
=
re
.
compile
(
r"^(.*)\
|(.*)
\|(.*) <type '(.*)'> / <type '(.*)'>$"
).
match
...
...
@@ -46,7 +47,7 @@ def analyze_data(data):
return
False
class
FixDivision
(
BaseFix
):
class
FixDivision
Support
(
BaseFix
):
"""Rewrites division_traced(n, a, b) into Py2/Py3-compatible division
The `TRACE_FILE` environment variable must point to the trace data file. See
...
...
@@ -62,7 +63,7 @@ class FixDivision(BaseFix):
"""
def
start_tree
(
self
,
tree
,
filename
):
super
(
FixDivision
,
self
).
start_tree
(
tree
,
filename
)
super
(
FixDivision
Support
,
self
).
start_tree
(
tree
,
filename
)
self
.
absolute_filename
=
os
.
path
.
abspath
(
filename
)
...
...
my2to3/fixes/fix_
trace_division
.py
→
my2to3/fixes/fix_
division_trace
.py
View file @
f730910d
...
...
@@ -6,10 +6,10 @@ from lib2to3.pygram import python_symbols as syms
from
lib2to3.pytree
import
Node
import
sys
from
my2to3.
util
import
BaseFix
from
my2to3.
fixes
import
BaseFix
class
Fix
TraceDivision
(
BaseFix
):
class
Fix
DivisionTrace
(
BaseFix
):
"""Rewrites a/b into division_traced(a, b)
division_traced can be a function that looks up the stack and record the operand types, for example:
...
...
@@ -30,7 +30,7 @@ class FixTraceDivision(BaseFix):
__builtin__.division_traced = division_traced
"""
def
start_tree
(
self
,
tree
,
filename
):
super
(
Fix
TraceDivision
,
self
).
start_tree
(
tree
,
filename
)
super
(
Fix
DivisionTrace
,
self
).
start_tree
(
tree
,
filename
)
self
.
ids
=
defaultdict
(
int
)
def
match
(
self
,
node
):
...
...
my2to3/tests/testFix
TraceDivision
.py
→
my2to3/tests/testFix
DivisionTrace
.py
View file @
f730910d
...
...
@@ -9,7 +9,7 @@ class FixerTestCase(lib2to3FixerTestCase):
class
testFixTraceDivision
(
FixerTestCase
):
fixer
=
"
trace_division
"
fixer
=
"
division_trace
"
def
test_simple_division
(
self
):
b
=
"""x / y"""
...
...
my2to3/util.py
View file @
f730910d
from
lib2to3
import
fixer_util
import
lib2to3.fixer_base
from
lib2to3.pytree
import
Leaf
,
Node
from
lib2to3.pgen2
import
token
from
lib2to3.pygram
import
python_symbols
as
syms
import
os
class
BaseFix
(
lib2to3
.
fixer_base
.
BaseFix
):
def
start_tree
(
self
,
tree
,
filename
):
sep
=
'-'
*
5
# Arbitrary
if
sep
in
filename
:
filename
=
filename
.
split
(
sep
,
1
)[
1
].
replace
(
sep
,
os
.
sep
)
super
(
BaseFix
,
self
).
start_tree
(
tree
,
filename
)
# https://github.com/python-modernize/python-modernize/blob/84d973cb7b8153f9f7f22c3574a59312b2372ccb/libmodernize/__init__.py#L10-49
...
...
@@ -58,7 +47,6 @@ def check_future_import(node):
assert
0
,
"strange import"
# https://github.com/python-modernize/python-modernize/blob/84d973cb7b8153f9f7f22c3574a59312b2372ccb/libmodernize/__init__.py#L51-L66
def
add_future
(
node
,
symbol
):
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment