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
8085b80c
Kaydet (Commit)
8085b80c
authored
May 18, 2015
tarafından
Yury Selivanov
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Issue 24226: Fix parsing of many sequential one-line 'def' statements.
üst
a2c145c2
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
51 additions
and
8 deletions
+51
-8
test_coroutines.py
Lib/test/test_coroutines.py
+23
-0
test_tokenize.py
Lib/test/test_tokenize.py
+11
-0
tokenizer.c
Parser/tokenizer.c
+17
-8
No files found.
Lib/test/test_coroutines.py
Dosyayı görüntüle @
8085b80c
import
contextlib
import
inspect
import
sys
import
types
import
unittest
...
...
@@ -87,6 +88,28 @@ class AsyncBadSyntaxTest(unittest.TestCase):
import
test.badsyntax_async9
class
TokenizerRegrTest
(
unittest
.
TestCase
):
def
test_oneline_defs
(
self
):
buf
=
[]
for
i
in
range
(
500
):
buf
.
append
(
'def i{i}(): return {i}'
.
format
(
i
=
i
))
buf
=
'
\n
'
.
join
(
buf
)
# Test that 500 consequent, one-line defs is OK
ns
=
{}
exec
(
buf
,
ns
,
ns
)
self
.
assertEqual
(
ns
[
'i499'
](),
499
)
# Test that 500 consequent, one-line defs *and*
# one 'async def' following them is OK
buf
+=
'
\n
async def foo():
\n
return'
ns
=
{}
exec
(
buf
,
ns
,
ns
)
self
.
assertEqual
(
ns
[
'i499'
](),
499
)
self
.
assertTrue
(
inspect
.
iscoroutinefunction
(
ns
[
'foo'
]))
class
CoroutineTest
(
unittest
.
TestCase
):
def
test_gen_1
(
self
):
...
...
Lib/test/test_tokenize.py
Dosyayı görüntüle @
8085b80c
...
...
@@ -1289,6 +1289,17 @@ class TestTokenize(TestCase):
self
.
assertTrue
(
encoding_used
,
encoding
)
def
test_oneline_defs
(
self
):
buf
=
[]
for
i
in
range
(
500
):
buf
.
append
(
'def i{i}(): return {i}'
.
format
(
i
=
i
))
buf
.
append
(
'OK'
)
buf
=
'
\n
'
.
join
(
buf
)
# Test that 500 consequent, one-line defs is OK
toks
=
list
(
tokenize
(
BytesIO
(
buf
.
encode
(
'utf-8'
))
.
readline
))
self
.
assertEqual
(
toks
[
-
2
]
.
string
,
'OK'
)
# [-1] is always ENDMARKER
def
assertExactTypeEqual
(
self
,
opstr
,
*
optypes
):
tokens
=
list
(
tokenize
(
BytesIO
(
opstr
.
encode
(
'utf-8'
))
.
readline
))
num_optypes
=
len
(
optypes
)
...
...
Parser/tokenizer.c
Dosyayı görüntüle @
8085b80c
...
...
@@ -1501,17 +1501,20 @@ tok_get(struct tok_state *tok, char **p_start, char **p_end)
tok_len
=
tok
->
cur
-
tok
->
start
;
if
(
tok_len
==
3
&&
memcmp
(
tok
->
start
,
"def"
,
3
)
==
0
)
{
if
(
tok
->
def
+
1
>=
MAXINDENT
)
{
tok
->
done
=
E_TOODEEP
;
tok
->
cur
=
tok
->
inp
;
return
ERRORTOKEN
;
}
if
(
tok
->
def
&&
tok
->
deftypestack
[
tok
->
def
]
==
3
)
{
tok
->
deftypestack
[
tok
->
def
]
=
2
;
}
else
{
else
if
(
tok
->
defstack
[
tok
->
def
]
<
tok
->
indent
)
{
/* We advance defs stack only when we see "def" *and*
the indentation level was increased relative to the
previous "def". */
if
(
tok
->
def
+
1
>=
MAXINDENT
)
{
tok
->
done
=
E_TOODEEP
;
tok
->
cur
=
tok
->
inp
;
return
ERRORTOKEN
;
}
tok
->
def
++
;
tok
->
defstack
[
tok
->
def
]
=
tok
->
indent
;
tok
->
deftypestack
[
tok
->
def
]
=
1
;
...
...
@@ -1528,6 +1531,12 @@ tok_get(struct tok_state *tok, char **p_start, char **p_end)
ahead_tok
.
cur
-
ahead_tok
.
start
==
3
&&
memcmp
(
ahead_tok
.
start
,
"def"
,
3
)
==
0
)
{
if
(
tok
->
def
+
1
>=
MAXINDENT
)
{
tok
->
done
=
E_TOODEEP
;
tok
->
cur
=
tok
->
inp
;
return
ERRORTOKEN
;
}
tok
->
def
++
;
tok
->
defstack
[
tok
->
def
]
=
tok
->
indent
;
tok
->
deftypestack
[
tok
->
def
]
=
3
;
...
...
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