mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-12-23 03:02:52 +01:00
Add 2to3 fixer to process utils.gen.IterableMap correctly.
This commit is contained in:
parent
5a35c7fafd
commit
32a7da6f51
22
2to3/fix_def_iteritems.py
Normal file
22
2to3/fix_def_iteritems.py
Normal file
@ -0,0 +1,22 @@
|
||||
"""Fixer for iteritems -> items methods."""
|
||||
# Author: Valentin Lorentz
|
||||
|
||||
# Code modified from fix_nonzero by Collin Winter
|
||||
|
||||
from lib2to3 import fixer_base
|
||||
from lib2to3.fixer_util import Name, syms
|
||||
|
||||
class FixDefIteritems(fixer_base.BaseFix):
|
||||
BM_compatible = True
|
||||
PATTERN = """
|
||||
classdef< 'class' any+ ':'
|
||||
suite< any*
|
||||
funcdef< 'def' name='iteritems'
|
||||
parameters< '(' NAME ')' > any+ >
|
||||
any* > >
|
||||
"""
|
||||
|
||||
def transform(self, node, results):
|
||||
name = results["name"]
|
||||
new = Name(u"items", prefix=name.prefix)
|
||||
name.replace(new)
|
22
2to3/fix_def_iterkeys.py
Normal file
22
2to3/fix_def_iterkeys.py
Normal file
@ -0,0 +1,22 @@
|
||||
"""Fixer for iterkeys -> keys methods."""
|
||||
# Author: Valentin Lorentz
|
||||
|
||||
# Code modified from fix_nonzero by Collin Winter
|
||||
|
||||
from lib2to3 import fixer_base
|
||||
from lib2to3.fixer_util import Name, syms
|
||||
|
||||
class FixDefIterkeys(fixer_base.BaseFix):
|
||||
BM_compatible = True
|
||||
PATTERN = """
|
||||
classdef< 'class' any+ ':'
|
||||
suite< any*
|
||||
funcdef< 'def' name='iterkeys'
|
||||
parameters< '(' NAME ')' > any+ >
|
||||
any* > >
|
||||
"""
|
||||
|
||||
def transform(self, node, results):
|
||||
name = results["name"]
|
||||
new = Name(u"keys", prefix=name.prefix)
|
||||
name.replace(new)
|
22
2to3/fix_def_itervalues.py
Normal file
22
2to3/fix_def_itervalues.py
Normal file
@ -0,0 +1,22 @@
|
||||
"""Fixer for itervalues -> values methods."""
|
||||
# Author: Valentin Lorentz
|
||||
|
||||
# Code modified from fix_nonzero by Collin Winter
|
||||
|
||||
from lib2to3 import fixer_base
|
||||
from lib2to3.fixer_util import Name, syms
|
||||
|
||||
class FixDefItervalues(fixer_base.BaseFix):
|
||||
BM_compatible = True
|
||||
PATTERN = """
|
||||
classdef< 'class' any+ ':'
|
||||
suite< any*
|
||||
funcdef< 'def' name='itervalues'
|
||||
parameters< '(' NAME ')' > any+ >
|
||||
any* > >
|
||||
"""
|
||||
|
||||
def transform(self, node, results):
|
||||
name = results["name"]
|
||||
new = Name(u"values", prefix=name.prefix)
|
||||
name.replace(new)
|
12
2to3/run.py
Normal file
12
2to3/run.py
Normal file
@ -0,0 +1,12 @@
|
||||
#! /usr/bin/python2.7
|
||||
import sys
|
||||
from lib2to3.main import main
|
||||
|
||||
import fix_def_iteritems, fix_def_itervalues, fix_def_iterkeys
|
||||
|
||||
# Hacks
|
||||
sys.modules['lib2to3.fixes.fix_def_iteritems'] = fix_def_iteritems
|
||||
sys.modules['lib2to3.fixes.fix_def_itervalues'] = fix_def_itervalues
|
||||
sys.modules['lib2to3.fixes.fix_def_iterkeys'] = fix_def_iterkeys
|
||||
|
||||
sys.exit(main("lib2to3.fixes"))
|
1
sandbox/run_2to3.sh
Executable file
1
sandbox/run_2to3.sh
Executable file
@ -0,0 +1 @@
|
||||
python 2to3/run.py src/ plugins/ test/ scripts/* setup.py -wn -f all -f def_iteritems -f def_itervalues -f def_iterkeys "$@"
|
@ -206,12 +206,14 @@ class IterableMap(object):
|
||||
def iterkeys(self):
|
||||
for (key, _) in self.iteritems():
|
||||
yield key
|
||||
__iter__ = iterkeys
|
||||
|
||||
def itervalues(self):
|
||||
for (_, value) in self.iteritems():
|
||||
yield value
|
||||
|
||||
if sys.version_info[0] < 3:
|
||||
# Our 2to3 fixers automatically rename iteritems/iterkeys/itervalues
|
||||
# to items/keys/values
|
||||
def items(self):
|
||||
return list(self.iteritems())
|
||||
|
||||
@ -220,6 +222,9 @@ class IterableMap(object):
|
||||
|
||||
def values(self):
|
||||
return list(self.itervalues())
|
||||
__iter__ = iterkeys
|
||||
else:
|
||||
__iter__ = items
|
||||
|
||||
def __len__(self):
|
||||
ret = 0
|
||||
|
Loading…
Reference in New Issue
Block a user