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
Xavier Thompson
my2to3
Commits
3817aa59
Commit
3817aa59
authored
Jul 13, 2020
by
Bryton Lacquement
🚪
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
division_support: record the status of each modification
parent
c671076a
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
20 additions
and
10 deletions
+20
-10
my2to3/fixes/fix_division_support.py
my2to3/fixes/fix_division_support.py
+20
-10
No files found.
my2to3/fixes/fix_division_support.py
View file @
3817aa59
...
...
@@ -8,15 +8,23 @@ from my2to3.trace import get_data
from
my2to3.util
import
add_future
,
data2types
def
analyze_types
(
types
):
"""Indicates whether the division described by `data` should be modified into
`//`, or should remain as `/`
"""
if
len
(
types
)
==
1
:
dividend
,
divisor
=
types
[
0
]
if
dividend
is
divisor
is
int
:
return
True
return
False
# id is used to differentiate the divisions of the same line.
insert_support
=
create_table
(
"division_support"
,
"filename"
,
"lineno"
,
"id"
,
"status"
)
def
analyze_data
(
data
):
try
:
types
=
data2types
(
data
)
except
Exception
as
e
:
# Probably, one type is not a builtins
return
False
,
"unknown"
else
:
if
len
(
types
)
==
1
:
dividend
,
divisor
=
types
[
0
]
if
dividend
is
divisor
is
int
:
return
True
,
"automatic"
return
False
,
"manual"
class
FixDivisionSupport
(
BaseFix
):
...
...
@@ -35,7 +43,9 @@ class FixDivisionSupport(BaseFix):
if
not
data
:
return
if
analyze_types
(
data2types
(
data
)):
should_change
,
status
=
analyze_data
(
data
)
insert_support
(
filename
,
lineno
,
id_
,
status
)
if
should_change
:
add_future
(
node
,
'division'
)
operator
=
Leaf
(
lib2to3
.
pgen2
.
token
.
DOUBLESLASH
,
"//"
)
else
:
...
...
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