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
39a46687
Commit
39a46687
authored
Jun 08, 2020
by
Bryton Lacquement
🚪
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix_division: always replace with '//' (for now)
parent
a73f5fea
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
29 additions
and
2 deletions
+29
-2
my2to3/fixes/fix_division.py
my2to3/fixes/fix_division.py
+29
-2
No files found.
my2to3/fixes/fix_division.py
View file @
39a46687
import
builtins
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
...
...
@@ -30,6 +33,14 @@ def parse_trace_data(filepath):
return
traces
def
analyze_data
(
data
):
"""Indicates whether the division described by `data` should be modified into
`//`, or should remain as `/`
"""
# TODO:
return
True
class
FixDivision
(
lib2to3
.
fixer_base
.
BaseFix
):
"""Rewrites division_traced(n, a, b) into Py2/Py3-compatible division
...
...
@@ -55,5 +66,21 @@ class FixDivision(lib2to3.fixer_base.BaseFix):
id_
=
int
(
node
.
children
[
1
].
children
[
1
].
children
[
0
].
value
)
data
=
self
.
traces
[
self
.
absolute_filename
][
lineno
][
id_
]
if
not
data
:
return
# TODO: analyse `data`, and replace the node to rewrite code
if
analyze_data
(
data
):
operator
=
Leaf
(
lib2to3
.
pgen2
.
token
.
DOUBLESLASH
,
"//"
)
else
:
operator
=
Leaf
(
lib2to3
.
pgen2
.
token
.
SLASH
,
"/"
)
operator
.
prefix
=
node
.
children
[
1
].
children
[
1
].
children
[
3
].
prefix
node
.
replace
(
Node
(
syms
.
term
,
[
node
.
children
[
1
].
children
[
1
].
children
[
2
].
clone
(),
operator
,
node
.
children
[
1
].
children
[
1
].
children
[
4
].
clone
()
],
prefix
=
node
.
prefix
))
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