Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
P
pepallow
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
9
Konular (issue)
9
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
pepallow
Commits
bf16623c
Kaydet (Commit)
bf16623c
authored
Nis 07, 2019
tarafından
Batuhan Taşkaya
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Sade Fark
Merge branch 'master' of github.com:abstractequalsmagic/pepallow
üst
1067b23d
de7cfa27
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
31 additions
and
62 deletions
+31
-62
example.py
examples/example.py
+7
-6
__init__.py
pepallow/__init__.py
+0
-1
allow.py
pepallow/allow.py
+6
-12
p211.py
pepallow/peps/p211.py
+3
-5
p231.py
pepallow/peps/p231.py
+11
-30
p313.py
pepallow/peps/p313.py
+0
-1
p377.py
pepallow/peps/p377.py
+3
-6
setup.py
setup.py
+1
-1
No files found.
examples/example.py
Dosyayı görüntüle @
bf16623c
...
...
@@ -4,16 +4,16 @@ from pepallow.peps.p231 import AssetBean as Bean
with
Allow
(
211
):
s
=
[
1
,
2
,
3
]
t
=
"abc"
product
=
[]
counter
=
0
for
i
,
j
in
s
@
t
:
product
.
append
(
f
"{i}{j}"
)
counter
+=
1
assert
counter
==
9
assert
product
==
[
"1a"
,
"1b"
,
"1c"
,
"2a"
,
"2b"
,
"2c"
,
"3a"
,
"3b"
,
"3c"
]
assert
product
==
[
'1a'
,
'1b'
,
'1c'
,
'2a'
,
'2b'
,
'2c'
,
'3a'
,
'3b'
,
'3c'
]
with
Allow
(
231
):
b
=
Bean
(
3
)
assert
b
.
foo
==
3
...
...
@@ -26,11 +26,12 @@ with Allow(276):
for
number
in
10
:
items
.
append
(
number
)
counter
+=
1
assert
counter
==
10
assert
sum
(
items
)
==
45
with
Allow
(
313
):
assert
IV
+
I
==
V
assert
VI
+
M
==
1006
assert
(
M
-
D
)
+
VI
-
X
==
(
500
)
+
6
-
10
pepallow/__init__.py
Dosyayı görüntüle @
bf16623c
import
ast
class
HandledTransformer
(
ast
.
NodeTransformer
):
def
__init__
(
self
,
handler
,
*
args
,
**
kwargs
):
self
.
handler
=
handler
...
...
pepallow/allow.py
Dosyayı görüntüle @
bf16623c
...
...
@@ -21,30 +21,24 @@ class TreeHandler:
def
__init__
(
self
,
tree
):
self
.
tree
=
tree
self
.
_inserteds
=
set
()
def
set_global
(
self
,
itemid
,
item
):
self
.
_inserteds
.
add
(
itemid
)
self
.
tree
.
body
=
[
item
]
+
self
.
tree
.
body
# self.tree.body.insert(0, item)
self
.
tree
.
body
=
[
item
]
+
self
.
tree
.
body
# self.tree.body.insert(0, item)
class
PEPTransformer
(
ast
.
NodeTransformer
):
def
visit
(
self
,
tree
):
if
isinstance
(
tree
,
ast
.
Module
):
self
.
handler
=
TreeHandler
(
tree
)
return
super
()
.
visit
(
tree
)
def
visit_With
(
self
,
node
):
if
(
isinstance
(
node
.
items
[
0
]
.
context_expr
,
ast
.
Call
)
and
isinstance
(
node
.
items
[
0
]
.
context_expr
.
func
,
ast
.
Name
)
and
node
.
items
[
0
]
.
context_expr
.
func
.
id
==
"Allow"
):
if
isinstance
(
node
.
items
[
0
]
.
context_expr
,
ast
.
Call
)
and
isinstance
(
node
.
items
[
0
]
.
context_expr
.
func
,
ast
.
Name
)
and
node
.
items
[
0
]
.
context_expr
.
func
.
id
==
"Allow"
:
pep
=
node
.
items
[
0
]
.
context_expr
.
args
[
0
]
.
n
new_node
=
PEPS
[
pep
][
"transformer"
](
self
.
handler
)
.
visit
(
node
)
ast
.
copy_location
(
new_node
,
node
)
ast
.
fix_missing_locations
(
new_node
)
return
node
...
...
pepallow/peps/p211.py
Dosyayı görüntüle @
bf16623c
...
...
@@ -23,12 +23,10 @@ class PEP211Transformer(HandledTransformer):
and
isinstance
(
node
.
iter
.
op
,
ast
.
MatMult
)
):
if
len
(
node
.
target
.
elts
)
<
2
:
raise
ValueError
(
f
"Not enough values to unpack (expected 2, got {len(node.target.elts)})"
)
raise
ValueError
(
f
"Not enough values to unpack (expected 2, got {len(node.target.elts)})"
)
elif
len
(
node
.
target
.
elts
)
>
2
:
raise
ValueError
(
"Too many values to unpack (expected 2)"
)
raise
ValueError
(
"Too many values to unpack (expected 2)"
)
a
,
b
=
node
.
target
.
elts
return
ast
.
For
(
target
=
a
,
...
...
pepallow/peps/p231.py
Dosyayı görüntüle @
bf16623c
...
...
@@ -7,18 +7,14 @@ class PEP231Transformer(HandledTransformer):
name
=
node
.
value
attr
=
node
.
attr
ctx
=
node
.
ctx
if
isinstance
(
ctx
,
ast
.
Load
):
node
=
ast
.
IfExp
(
ast
.
Call
(
ast
.
Name
(
"hasattr"
,
ast
.
Load
()),
[
name
,
ast
.
Str
(
"__findattr__"
)],
[]
),
ast
.
Call
(
ast
.
Attribute
(
name
,
"__findattr__"
,
ast
.
Load
()),
[
ast
.
Str
(
attr
)],
[]
),
ast
.
Call
(
ast
.
Name
(
"hasattr"
,
ast
.
Load
()),
[
name
,
ast
.
Str
(
"__findattr__"
)],
[]),
ast
.
Call
(
ast
.
Attribute
(
name
,
"__findattr__"
,
ast
.
Load
()),
[
ast
.
Str
(
attr
)],
[]),
orelse
=
ast
.
Attribute
(
name
,
attr
,
ctx
),
)
return
node
def
visit_Assign
(
self
,
node
):
...
...
@@ -27,27 +23,13 @@ class PEP231Transformer(HandledTransformer):
name
=
target
.
value
attr
=
target
.
attr
ctx
=
target
.
ctx
node
=
ast
.
Expr
(
ast
.
IfExp
(
ast
.
Call
(
ast
.
Name
(
"hasattr"
,
ast
.
Load
()),
[
name
,
ast
.
Str
(
"__findattr__"
)],
[],
),
ast
.
Call
(
ast
.
Attribute
(
name
,
"__findattr__"
,
ast
.
Load
()),
[
ast
.
Str
(
attr
),
node
.
value
],
[],
),
orelse
=
ast
.
Call
(
ast
.
Name
(
"setattr"
,
ast
.
Load
()),
[
name
,
ast
.
Str
(
attr
),
node
.
value
],
[],
),
)
)
node
=
ast
.
Expr
(
ast
.
IfExp
(
ast
.
Call
(
ast
.
Name
(
"hasattr"
,
ast
.
Load
()),
[
name
,
ast
.
Str
(
"__findattr__"
)],
[]),
ast
.
Call
(
ast
.
Attribute
(
name
,
"__findattr__"
,
ast
.
Load
()),
[
ast
.
Str
(
attr
),
node
.
value
],
[]),
orelse
=
ast
.
Call
(
ast
.
Name
(
"setattr"
,
ast
.
Load
()),
[
name
,
ast
.
Str
(
attr
),
node
.
value
],
[]),
))
return
node
...
...
@@ -55,7 +37,6 @@ class AssetBean:
"""
Directly copied from https://www.python.org/dev/peps/pep-0231/
"""
def
__init__
(
self
,
x
):
self
.
__myfoo
=
x
...
...
pepallow/peps/p313.py
Dosyayı görüntüle @
bf16623c
...
...
@@ -7,7 +7,6 @@ try:
except
ImportError
:
from
pepallow.romana
import
roman
class
PEP313Transformer
(
HandledTransformer
):
"""
PEP313 => Adding Roman Numeral Literals to Python
...
...
pepallow/peps/p377.py
Dosyayı görüntüle @
bf16623c
...
...
@@ -18,9 +18,9 @@ class PEP377Transformer(HandledTransformer):
],
[],
),
)
,
)
)
return
node
def
visit_With
(
self
,
node
):
...
...
@@ -36,10 +36,7 @@ class PEP377Transformer(HandledTransformer):
assign
=
(
ast
.
Pass
()
if
node
.
items
[
0
]
is
None
else
ast
.
Assign
(
[
node
.
items
[
0
]
.
optional_vars
],
ast
.
Name
(
"StatementSkipped"
,
ast
.
Load
()),
)
else
ast
.
Assign
([
node
.
items
[
0
]
.
optional_vars
],
ast
.
Name
(
"StatementSkipped"
,
ast
.
Load
()))
)
node
=
ast
.
Try
(
[
node
],
...
...
setup.py
Dosyayı görüntüle @
bf16623c
...
...
@@ -8,7 +8,7 @@ with open(current_dir / "README.md", encoding="utf-8") as f:
setup
(
name
=
"pepallow"
,
version
=
"0.3.
1
"
,
version
=
"0.3.
2
"
,
packages
=
find_packages
(),
url
=
"https://github.com/abstractequalsmagic/pepallow"
,
description
=
"Hack the interpreter for running rejected pep's changes."
,
...
...
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