Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
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)
0
Konular (issue)
0
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
cpython
Commits
4219da4b
Kaydet (Commit)
4219da4b
authored
Şub 25, 2008
tarafından
Facundo Batista
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Issue 2117. Update compiler module to handle class decorators.
Thanks Thomas Herve
üst
a3c8c102
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
21 additions
and
4 deletions
+21
-4
ast.py
Lib/compiler/ast.py
+6
-2
transformer.py
Lib/compiler/transformer.py
+12
-0
token.py
Lib/token.py
+1
-0
ast.txt
Tools/compiler/ast.txt
+2
-2
No files found.
Lib/compiler/ast.py
Dosyayı görüntüle @
4219da4b
...
@@ -308,11 +308,12 @@ class CallFunc(Node):
...
@@ -308,11 +308,12 @@ class CallFunc(Node):
return
"CallFunc(
%
s,
%
s,
%
s,
%
s)"
%
(
repr
(
self
.
node
),
repr
(
self
.
args
),
repr
(
self
.
star_args
),
repr
(
self
.
dstar_args
))
return
"CallFunc(
%
s,
%
s,
%
s,
%
s)"
%
(
repr
(
self
.
node
),
repr
(
self
.
args
),
repr
(
self
.
star_args
),
repr
(
self
.
dstar_args
))
class
Class
(
Node
):
class
Class
(
Node
):
def
__init__
(
self
,
name
,
bases
,
doc
,
code
,
lineno
=
None
):
def
__init__
(
self
,
name
,
bases
,
doc
,
code
,
decorators
=
None
,
lineno
=
None
):
self
.
name
=
name
self
.
name
=
name
self
.
bases
=
bases
self
.
bases
=
bases
self
.
doc
=
doc
self
.
doc
=
doc
self
.
code
=
code
self
.
code
=
code
self
.
decorators
=
decorators
self
.
lineno
=
lineno
self
.
lineno
=
lineno
def
getChildren
(
self
):
def
getChildren
(
self
):
...
@@ -321,16 +322,19 @@ class Class(Node):
...
@@ -321,16 +322,19 @@ class Class(Node):
children
.
extend
(
flatten
(
self
.
bases
))
children
.
extend
(
flatten
(
self
.
bases
))
children
.
append
(
self
.
doc
)
children
.
append
(
self
.
doc
)
children
.
append
(
self
.
code
)
children
.
append
(
self
.
code
)
children
.
append
(
self
.
decorators
)
return
tuple
(
children
)
return
tuple
(
children
)
def
getChildNodes
(
self
):
def
getChildNodes
(
self
):
nodelist
=
[]
nodelist
=
[]
nodelist
.
extend
(
flatten_nodes
(
self
.
bases
))
nodelist
.
extend
(
flatten_nodes
(
self
.
bases
))
nodelist
.
append
(
self
.
code
)
nodelist
.
append
(
self
.
code
)
if
self
.
decorators
is
not
None
:
nodelist
.
append
(
self
.
decorators
)
return
tuple
(
nodelist
)
return
tuple
(
nodelist
)
def
__repr__
(
self
):
def
__repr__
(
self
):
return
"Class(
%
s,
%
s,
%
s,
%
s
)"
%
(
repr
(
self
.
name
),
repr
(
self
.
bases
),
repr
(
self
.
doc
),
repr
(
self
.
code
))
return
"Class(
%
s,
%
s,
%
s,
%
s
,
%
s)"
%
(
repr
(
self
.
name
),
repr
(
self
.
bases
),
repr
(
self
.
doc
),
repr
(
self
.
code
),
repr
(
self
.
decorators
))
class
Compare
(
Node
):
class
Compare
(
Node
):
def
__init__
(
self
,
expr
,
ops
,
lineno
=
None
):
def
__init__
(
self
,
expr
,
ops
,
lineno
=
None
):
...
...
Lib/compiler/transformer.py
Dosyayı görüntüle @
4219da4b
...
@@ -232,6 +232,18 @@ class Transformer:
...
@@ -232,6 +232,18 @@ class Transformer:
items
.
append
(
self
.
decorator
(
dec_nodelist
[
1
:]))
items
.
append
(
self
.
decorator
(
dec_nodelist
[
1
:]))
return
Decorators
(
items
)
return
Decorators
(
items
)
def
decorated
(
self
,
nodelist
):
assert
nodelist
[
0
][
0
]
==
symbol
.
decorators
if
nodelist
[
1
][
0
]
==
symbol
.
funcdef
:
n
=
[
nodelist
[
0
]]
+
list
(
nodelist
[
1
][
1
:])
return
self
.
funcdef
(
n
)
elif
nodelist
[
1
][
0
]
==
symbol
.
classdef
:
decorators
=
self
.
decorators
(
nodelist
[
0
][
1
:])
cls
=
self
.
classdef
(
nodelist
[
1
][
1
:])
cls
.
decorators
=
decorators
return
cls
raise
WalkerError
()
def
funcdef
(
self
,
nodelist
):
def
funcdef
(
self
,
nodelist
):
# -6 -5 -4 -3 -2 -1
# -6 -5 -4 -3 -2 -1
# funcdef: [decorators] 'def' NAME parameters ':' suite
# funcdef: [decorators] 'def' NAME parameters ':' suite
...
...
Lib/token.py
Dosyayı görüntüle @
4219da4b
...
@@ -71,6 +71,7 @@ tok_name = {}
...
@@ -71,6 +71,7 @@ tok_name = {}
for
_name
,
_value
in
globals
()
.
items
():
for
_name
,
_value
in
globals
()
.
items
():
if
type
(
_value
)
is
type
(
0
):
if
type
(
_value
)
is
type
(
0
):
tok_name
[
_value
]
=
_name
tok_name
[
_value
]
=
_name
del
_name
,
_value
def
ISTERMINAL
(
x
):
def
ISTERMINAL
(
x
):
...
...
Tools/compiler/ast.txt
Dosyayı görüntüle @
4219da4b
...
@@ -14,7 +14,7 @@ Stmt: nodes!
...
@@ -14,7 +14,7 @@ Stmt: nodes!
Decorators: nodes!
Decorators: nodes!
Function: decorators&, name*, argnames*, defaults!, flags*, doc*, code
Function: decorators&, name*, argnames*, defaults!, flags*, doc*, code
Lambda: argnames*, defaults!, flags*, code
Lambda: argnames*, defaults!, flags*, code
Class: name*, bases!, doc*, code
Class: name*, bases!, doc*, code
, decorators& = None
Pass:
Pass:
Break:
Break:
Continue:
Continue:
...
@@ -97,7 +97,7 @@ init(Lambda):
...
@@ -97,7 +97,7 @@ init(Lambda):
self.kwargs = 1
self.kwargs = 1
init(GenExpr):
init(GenExpr):
self.argnames = ['
[outmost-iterable]
']
self.argnames = ['
.0
']
self.varargs = self.kwargs = None
self.varargs = self.kwargs = None
init(GenExprFor):
init(GenExprFor):
...
...
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