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
28325749
Kaydet (Commit)
28325749
authored
Eyl 10, 2016
tarafından
Gregory P. Smith ext:(%20%5BGoogle%20Inc.%5D)
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Issue #25969: Update the lib2to3 grammar to handle the unpacking
generalizations added in 3.5.
üst
dbdf029a
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
91 additions
and
6 deletions
+91
-6
Grammar.txt
Lib/lib2to3/Grammar.txt
+17
-6
fix_apply.py
Lib/lib2to3/fixes/fix_apply.py
+11
-0
fix_intern.py
Lib/lib2to3/fixes/fix_intern.py
+10
-0
fix_reload.py
Lib/lib2to3/fixes/fix_reload.py
+11
-0
test_fixers.py
Lib/lib2to3/tests/test_fixers.py
+4
-0
test_parser.py
Lib/lib2to3/tests/test_parser.py
+35
-0
NEWS
Misc/NEWS
+3
-0
No files found.
Lib/lib2to3/Grammar.txt
Dosyayı görüntüle @
28325749
...
...
@@ -138,15 +138,26 @@ subscript: test | [test] ':' [test] [sliceop]
sliceop: ':' [test]
exprlist: (expr|star_expr) (',' (expr|star_expr))* [',']
testlist: test (',' test)* [',']
dictsetmaker: ( (test ':' test (comp_for | (',' test ':' test)* [','])) |
(test (comp_for | (',' test)* [','])) )
dictsetmaker: ( ((test ':' test | '**' expr)
(comp_for | (',' (test ':' test | '**' expr))* [','])) |
((test | star_expr)
(comp_for | (',' (test | star_expr))* [','])) )
classdef: 'class' NAME ['(' [arglist] ')'] ':' suite
arglist: (argument ',')* (argument [',']
|'*' test (',' argument)* [',' '**' test]
|'**' test)
argument: test [comp_for] | test '=' test # Really [keyword '='] test
arglist: argument (',' argument)* [',']
# "test '=' test" is really "keyword '=' test", but we have no such token.
# These need to be in a single rule to avoid grammar that is ambiguous
# to our LL(1) parser. Even though 'test' includes '*expr' in star_expr,
# we explicitly match '*' here, too, to give it proper precedence.
# Illegal combinations and orderings are blocked in ast.c:
# multiple (test comp_for) arguements are blocked; keyword unpackings
# that precede iterable unpackings are blocked; etc.
argument: ( test [comp_for] |
test '=' test |
'**' expr |
star_expr )
comp_iter: comp_for | comp_if
comp_for: 'for' exprlist 'in' testlist_safe [comp_iter]
...
...
Lib/lib2to3/fixes/fix_apply.py
Dosyayı görüntüle @
28325749
...
...
@@ -34,6 +34,17 @@ class FixApply(fixer_base.BaseFix):
func
=
results
[
"func"
]
args
=
results
[
"args"
]
kwds
=
results
.
get
(
"kwds"
)
# I feel like we should be able to express this logic in the
# PATTERN above but I don't know how to do it so...
if
args
:
if
args
.
type
==
self
.
syms
.
star_expr
:
return
# Make no change.
if
(
args
.
type
==
self
.
syms
.
argument
and
args
.
children
[
0
]
.
value
==
'**'
):
return
# Make no change.
if
kwds
and
(
kwds
.
type
==
self
.
syms
.
argument
and
kwds
.
children
[
0
]
.
value
==
'**'
):
return
# Make no change.
prefix
=
node
.
prefix
func
=
func
.
clone
()
if
(
func
.
type
not
in
(
token
.
NAME
,
syms
.
atom
)
and
...
...
Lib/lib2to3/fixes/fix_intern.py
Dosyayı görüntüle @
28325749
...
...
@@ -25,6 +25,16 @@ class FixIntern(fixer_base.BaseFix):
"""
def
transform
(
self
,
node
,
results
):
if
results
:
# I feel like we should be able to express this logic in the
# PATTERN above but I don't know how to do it so...
obj
=
results
[
'obj'
]
if
obj
:
if
obj
.
type
==
self
.
syms
.
star_expr
:
return
# Make no change.
if
(
obj
.
type
==
self
.
syms
.
argument
and
obj
.
children
[
0
]
.
value
==
'**'
):
return
# Make no change.
names
=
(
'sys'
,
'intern'
)
new
=
ImportAndCall
(
node
,
results
,
names
)
touch_import
(
None
,
'sys'
,
node
)
...
...
Lib/lib2to3/fixes/fix_reload.py
Dosyayı görüntüle @
28325749
...
...
@@ -22,6 +22,17 @@ class FixReload(fixer_base.BaseFix):
"""
def
transform
(
self
,
node
,
results
):
if
results
:
# I feel like we should be able to express this logic in the
# PATTERN above but I don't know how to do it so...
obj
=
results
[
'obj'
]
print
(
'obj:'
,
repr
(
obj
))
if
obj
:
if
obj
.
type
==
self
.
syms
.
star_expr
:
return
# Make no change.
if
(
obj
.
type
==
self
.
syms
.
argument
and
obj
.
children
[
0
]
.
value
==
'**'
):
return
# Make no change.
names
=
(
'imp'
,
'reload'
)
new
=
ImportAndCall
(
node
,
results
,
names
)
touch_import
(
None
,
'imp'
,
node
)
...
...
Lib/lib2to3/tests/test_fixers.py
Dosyayı görüntüle @
28325749
...
...
@@ -260,6 +260,10 @@ class Test_apply(FixerTestCase):
s
=
"""apply(f, *args)"""
self
.
unchanged
(
s
)
def
test_unchanged_6b
(
self
):
s
=
"""apply(f, **kwds)"""
self
.
unchanged
(
s
)
def
test_unchanged_7
(
self
):
s
=
"""apply(func=f, args=args, kwds=kwds)"""
self
.
unchanged
(
s
)
...
...
Lib/lib2to3/tests/test_parser.py
Dosyayı görüntüle @
28325749
...
...
@@ -208,6 +208,41 @@ class TestRaiseChanges(GrammarTest):
self
.
invalid_syntax
(
"raise E from"
)
# Modelled after Lib/test/test_grammar.py:TokenTests.test_funcdef issue2292
# and Lib/test/text_parser.py test_list_displays, test_set_displays,
# test_dict_displays, test_argument_unpacking, ... changes.
class
TestUnpackingGeneralizations
(
GrammarTest
):
def
test_mid_positional_star
(
self
):
self
.
validate
(
"""func(1, *(2, 3), 4)"""
)
def
test_double_star_dict_literal
(
self
):
self
.
validate
(
"""func(**{'eggs':'scrambled', 'spam':'fried'})"""
)
def
test_double_star_dict_literal_after_keywords
(
self
):
self
.
validate
(
"""func(spam='fried', **{'eggs':'scrambled'})"""
)
def
test_list_display
(
self
):
self
.
validate
(
"""[*{2}, 3, *[4]]"""
)
def
test_set_display
(
self
):
self
.
validate
(
"""{*{2}, 3, *[4]}"""
)
def
test_dict_display_1
(
self
):
self
.
validate
(
"""{**{}}"""
)
def
test_dict_display_2
(
self
):
self
.
validate
(
"""{**{}, 3:4, **{5:6, 7:8}}"""
)
def
test_argument_unpacking_1
(
self
):
self
.
validate
(
"""f(a, *b, *c, d)"""
)
def
test_argument_unpacking_2
(
self
):
self
.
validate
(
"""f(**a, **b)"""
)
def
test_argument_unpacking_3
(
self
):
self
.
validate
(
"""f(2, *a, *b, **b, **c, **d)"""
)
# Adapted from Python 3's Lib/test/test_grammar.py:GrammarTests.testFuncdef
class
TestFunctionAnnotations
(
GrammarTest
):
def
test_1
(
self
):
...
...
Misc/NEWS
Dosyayı görüntüle @
28325749
...
...
@@ -65,6 +65,9 @@ Core and Builtins
Library
-------
-
Issue
#
25969
:
Update
the
lib2to3
grammar
to
handle
the
unpacking
generalizations
added
in
3.5
.
-
Issue
#
27932
:
Fixes
memory
leak
in
platform
.
win32_ver
()
-
Issue
#
14977
:
mailcap
now
respects
the
order
of
the
lines
in
the
mailcap
...
...
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