PEP 498: the Monologue
Mariatta Wijaya
@mariatta
PyCon Australia 2017 @pyconau
Slide 2
Who are you?
Hello!
!
Slide 3
Are you
…
… new to Python?
Slide 4
Are you
…
… only familiar with one PEP?
Slide 5
Are you
…
… using Python < 3.6?
Slide 6
Who am I?
Slide 7
PyLadies Vancouver Co-Organizer
Python Core Developer
@mariatta
Slide 8
What’s a PEP?
Slide 9
P
ython
E
nhancement
P
roposal
Slide 10
PEP 1:
PEP Purpose and Guideline
https://www.python.org/dev/peps/pep-0001
Slide 11
"
pitch to python-ideas
Slide 12
draft a PEP
Official template: PEP 12
alt template: pep_cookiecutter
$%
Slide 13
&
BDFL Pronouncement
'
(
Slide 14
429
PEPs today
82
rejected (~19%)
Slide 15
PEP 498
Slide 16
Have long wished python could format strings
easily like bash or perl do … and then it hit me
From:
Mike Miller
Subject:
[python-ideas] Briefer string format
Jul 20 01:12:31 CEST 2015
csstext += f'{nl}{selector}{space}{{{nl}'
I've seen others make similar suggestions, but to
my knowledge they didn’t include this
pleasing
brevity
aspect
.
https://mail.python.org/pipermail/python-ideas/2015-July/034657.html
Slide 17
From:
Eric V. Smith
Subject:
Re: [python-ideas] Briefer string format
Jul 20 01:12:31 CEST 2015
Jul 20 01:27:42 CEST 2015
What would this do?
https://mail.python.org/pipermail/python-ideas/2015-July/034658.html
Slide 18
From:
C. A.
Subject:
Re: [python-ideas] Briefer string format
Jul 20 01:12:31 CEST 2015
https://mail.python.org/pipermail/python-ideas/2015-July/034660.html
I’m
-1
on the specific idea, though definitely
sympathetic to the broader concept of simplified
formatting of strings.
Jul 20 01:44:09 CEST 2015
Jul 20 01:27:42 CEST 2015
Slide 19
From:
S. D.
Subject:
Re: [python-ideas] Briefer string format
It’s
syntactic sugar
for a simple function call with
perfectly well defined semantics - don’t even
have to modify the string literal.
I’m
+1
.
Jul 20 01:12:31 CEST 2015
Jul 20 01:27:42 CEST 2015
Jul 20 01:44:09 CEST 2015
Jul 20 02:43:29 CEST 2015
https://mail.python.org/pipermail/python-ideas/2015-July/034669.html
Slide 20
that escalated quickly
(
60+
replies later)
Slide 21
From:
Guido van Rossum
Subject:
Re: [python-ideas] Briefer string format
Jul 20 01:12:31 CEST 2015
Jul 20 01:27:42 CEST 2015
Jul 20 01:44:09 CEST 2015
Jul 20 02:43:29 CEST 2015
Jul 21 08:05:17 CEST 2015
Thanks, Eric! You’re addressing all my concerns
and you’re going exactly where I wanted this to
go.
I hope that you will find the time to write
up a PEP;
https://mail.python.org/pipermail/python-ideas/2015-July/034729.html
Slide 22
PEP 498:
Literal String Formatting
by: Eric V. Smith
August 7th, 2015
Slide 23
PEP 498:
Literal String Interpolation
August 7th, 2015
August 30th, 2015
by: Eric V. Smith
Slide 24
PEP 498:
Literal String Interpolation
ready
for pronouncement
August 7th, 2015
August 30th, 2015
September 5th, 2015
Slide 25
PEP 498:
Literal String Interpolation
August 7th, 2015
August 30th, 2015
September 7th, 2015
September 5th, 2015
Slide 26
“The existing ways of formatting are either
error prone
,
inflexible
, or
cumbersome
.”
RATIONALE
Slide 27
name =
"Bart"
print(
"Hello,
%s
."
% name)
Hello, Bart.
Slide 28
name =
"Bart"
age =
10
print(
"Hello,
%s
. You’re
%s
."
% name, age
)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: not enough arguments for format string
Slide 29
name =
"Bart"
age =
10
print(
"Hello,
%s
. You’re
%s
."
%
(
name, age
)
)
Hello, Bart. You're 10.
Slide 30
PEP 3101: str.format
https://www.python.org/dev/peps/pep-3101
Slide 31
name =
"Bart"
age =
10
print(
"Hello,
{name}
. You’re
{age}
.
"
.format(
name
=name,
age
=age))
Hello, Bart. You're 10.
Slide 32
PEP 498: f-string
https://www.python.org/dev/peps/pep-0498
Slide 33
name =
"Bart"
age =
10
print(
"Hello,
{name}
. You’re
{age}
.
"
.format(
name
=name,
age
=age))
...
"Make a purchase before
{tomorrow:%Y-%b-%d}
"
)
bpo-29668
Slide 52
✅
multiline strings
message = (
f
"Dear
{name}
,"
...
f
”You can win
{prize:.2f}
$"
...
f
"Make a purchase before
{tomorrow}:%Y-%b-%d
"
)
bpo-29668
Slide 53
IDLE needs syntax highlighting
bpo-29287
•
Needs separate colorization to make the expression distinct
from the rest of the string.
•
Needs close-brace matching.
•
Would be desirable to have autocompletion as well.