Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
93e51aac
Commit
93e51aac
authored
Jun 07, 2014
by
Benjamin Peterson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
allow the keyword else immediately after (no space) an integer (closes #21642)
parent
4807dd04
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
24 additions
and
5 deletions
+24
-5
Lib/test/test_grammar.py
Lib/test/test_grammar.py
+6
-0
Misc/NEWS
Misc/NEWS
+4
-0
Parser/tokenizer.c
Parser/tokenizer.c
+14
-5
No files found.
Lib/test/test_grammar.py
View file @
93e51aac
...
...
@@ -75,6 +75,12 @@ class TokenTests(unittest.TestCase):
x
=
.
3e14
x
=
3.1e4
def
test_float_exponent_tokenization
(
self
):
# See issue 21642.
self
.
assertEqual
(
1
if
1
else
0
,
1
)
self
.
assertEqual
(
1
if
0
else
0
,
0
)
self
.
assertRaises
(
SyntaxError
,
eval
,
"0 if 1Else 0"
)
def
testStringLiterals
(
self
):
x
=
''
;
y
=
""
;
self
.
assertTrue
(
len
(
x
)
==
0
and
x
==
y
)
x
=
'
\
'
'
;
y
=
"'"
;
self
.
assertTrue
(
len
(
x
)
==
1
and
x
==
y
and
ord
(
x
)
==
39
)
...
...
Misc/NEWS
View file @
93e51aac
...
...
@@ -13,6 +13,10 @@ Core and Builtins
- Issue #19656: Running Python with the -3 option now also warns about
non-ascii bytes literals.
- Issue #21642: If the conditional if-else expression, allow an integer written
with no space between itself and the ``else`` keyword (e.g. ``True if 42else
False``) to be valid syntax.
- Issue #21523: Fix over-pessimistic computation of the stack effect of
some opcodes in the compiler. This also fixes a quadratic compilation
time issue noticeable when compiling code with a large number of "and"
...
...
Parser/tokenizer.c
View file @
93e51aac
...
...
@@ -1500,15 +1500,24 @@ tok_get(register struct tok_state *tok, char **p_start, char **p_end)
}
while
(
isdigit
(
c
));
}
if
(
c
==
'e'
||
c
==
'E'
)
{
exponent:
int
e
;
exponent:
e
=
c
;
/* Exponent part */
c
=
tok_nextc
(
tok
);
if
(
c
==
'+'
||
c
==
'-'
)
if
(
c
==
'+'
||
c
==
'-'
)
{
c
=
tok_nextc
(
tok
);
if
(
!
isdigit
(
c
))
{
tok
->
done
=
E_TOKEN
;
if
(
!
isdigit
(
c
))
{
tok
->
done
=
E_TOKEN
;
tok_backup
(
tok
,
c
);
return
ERRORTOKEN
;
}
}
else
if
(
!
isdigit
(
c
))
{
tok_backup
(
tok
,
c
);
return
ERRORTOKEN
;
tok_backup
(
tok
,
e
);
*
p_start
=
tok
->
start
;
*
p_end
=
tok
->
cur
;
return
NUMBER
;
}
do
{
c
=
tok_nextc
(
tok
);
...
...
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