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
Bryton Lacquement
my2to3
Commits
61cdede9
Commit
61cdede9
authored
Jun 29, 2020
by
Bryton Lacquement
🚪
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
New BaseFix class
parent
742b6566
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
16 additions
and
5 deletions
+16
-5
my2to3/fixes/fix_division.py
my2to3/fixes/fix_division.py
+2
-3
my2to3/fixes/fix_trace_division.py
my2to3/fixes/fix_trace_division.py
+3
-2
my2to3/util.py
my2to3/util.py
+11
-0
No files found.
my2to3/fixes/fix_division.py
View file @
61cdede9
import
__builtin__
from
collections
import
defaultdict
import
lib2to3.fixer_base
import
lib2to3.pgen2
from
lib2to3.pygram
import
python_symbols
as
syms
from
lib2to3.pytree
import
Leaf
,
Node
import
os
import
re
from
my2to3.util
import
add_future
from
my2to3.util
import
add_future
,
BaseFix
trace_file_match
=
re
.
compile
(
r"^(.*)\
|(.*)
\|(.*) <type '(.*)'> / <type '(.*)'>$"
).
match
...
...
@@ -47,7 +46,7 @@ def analyze_data(data):
return
False
class
FixDivision
(
lib2to3
.
fixer_base
.
BaseFix
):
class
FixDivision
(
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
...
...
my2to3/fixes/fix_trace_division.py
View file @
61cdede9
# https://lab.nexedi.com/nexedi/erp5/snippets/475
from
collections
import
defaultdict
import
lib2to3.fixer_base
import
lib2to3.fixer_util
import
lib2to3.pgen2
from
lib2to3.pygram
import
python_symbols
as
syms
from
lib2to3.pytree
import
Node
import
sys
from
my2to3.util
import
BaseFix
class
FixTraceDivision
(
lib2to3
.
fixer_base
.
BaseFix
):
class
FixTraceDivision
(
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:
...
...
my2to3/util.py
View file @
61cdede9
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
...
...
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