Kaydet (Commit) c05e8416 authored tarafından Batuhan Taşkaya's avatar Batuhan Taşkaya

Merge branch 'master' of github.com:abstractequalsmagic/pepallow

......@@ -3,11 +3,13 @@ import sys
from contextlib import suppress, ExitStack
from pepallow.peps.p211 import PEP211Transformer
from pepallow.peps.p313 import PEP313Transformer
from pepallow.peps.p231 import PEP231Transformer
from pepallow.peps.p276 import PEP276Transformer
from pepallow.peps.p313 import PEP313Transformer
PEPS = {
211: {"transformer": PEP211Transformer(), "suppress": [TypeError]},
276: {"transformer": PEP276Transformer(), "suppress": [TypeError]},
231: {"transformer": PEP231Transformer(), "suppress": [AttributeError]},
313: {"transformer": PEP313Transformer(), "suppress": [NameError]},
}
......
......@@ -16,8 +16,20 @@ class PEP211Transformer(ast.NodeTransformer):
"""
def visit_For(self, node):
if isinstance(node.iter, ast.BinOp) and isinstance(node.iter.op, ast.MatMult):
node.iter = ast.Call(
ast.Name("zip", ast.Load()), [node.iter.left, node.iter.right], []
if (
isinstance(node.target, ast.Tuple)
and isinstance(node.iter, ast.BinOp)
and isinstance(node.iter.op, ast.MatMult)
):
if len(node.target.elts) != 2:
raise ValueError("There is should be only 2 names to unpack.")
a, b = node.target.elts
return ast.For(
target=a,
iter=node.iter.left,
body=[
ast.For(target=b, iter=node.iter.right, body=node.body, orelse=[])
],
orelse=node.orelse,
)
return node
import ast
class PEP276Transformer(ast.NodeTransformer):
"""
PEP276 => Iterator ints
for n in 3:
...
=>
for n in range(3):
...
"""
def visit_For(self, node):
if isinstance(node.iter, ast.Num):
if not isinstance(node.iter.n, int):
raise TypeError("The number should be integer, not float nor other number types.")
node.iter = ast.Call(ast.Name("range", ast.Load()), [node.iter], [])
return node
......@@ -6,7 +6,7 @@ https://github.com/abstractequalsmagic/romana/
"""
ROMAN_LITERALS = {
"I": 1,,
"I": 1,
"V": 5,
"X": 10,
"L": 50,
......@@ -30,4 +30,4 @@ def roman(roman_lit):
elif literal <= result:
result += literal
return result
return result
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment