[Python-Dev] Compiler hints to control how f-strings are construed

2015-08-21 Thread Barry Warsaw
On Aug 17, 2015, at 01:36 PM, Guido van Rossum wrote:

>> 1. Barry wants the substitutions to look like $identifier and possibly
>> ${identifier}, and the PEP 498 proposal just uses {}.
>>
>> 2. There needs to be a way to identify interpolated strings and i18n
>> strings, and possibly combinations of those. This leads to PEP 501's i-
>> and iu- strings.
>>
>> 3. A way to enforce identifiers-only, instead of generalized expressions.
>
>In an off-list message to Barry and Nick I came up with the same three
>points. :-)
>
>I think #2 is the hard one (unless we adopt a solution like Yury just
>proposed where you can have an arbitrary identifier in front of a string
>literal).

I've been heads-down on other things for a little while, but trying to
re-engage on this thread.  One thing that occurs to me now regarding points #1
and #3 is that, if we had a way to signal to the compiler how we wanted
f-strings (to use a helpful shorthand) to be parsed, we could solve both
problems and make the feature more useful for i18n.

I'm thinking something along the lines of __future__ imports, which already
influence how code in a module is construed.  If we had a similar way to hint
that f-strings should be construed in a way other than the default, I could do
something like:

from __string__ import f_strings_as_i18n

at the top of my module, and that would slot in the parser for PEP 292 strings
and no-arbitrary expressions.  I'd be fine with that.

There are some downsides of course.  I wouldn't be able to mix my simpler,
i18n-based strings with the default full-featured PEP 498/501 strings in the
same module.  I can live with that.

I don't see something like a context manager being appropriate for that use
case because it's a run-time behavior, even if the syntax would look
convenient.

The hints inside the __string__ module wouldn't be extensible, except by
modifying Python's stdlib.  E.g. if you wanted $-strings but full expression
support, we'd have to write and distribute that with stdlib.  I'm also fine
with this because I think there aren't really *that* many different use
cases.

(There's still #2 but let's deal with that later.)

>> 4. We need a "safe substitution" mode for str.format_map_simple (from
>> above).

Again, a `from __string__` import could solve that, right?

Cheers,
-Barry
___
Python-Dev mailing list
[email protected]
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


[Python-Dev] Summary of Python tracker Issues

2015-08-21 Thread Python tracker

ACTIVITY SUMMARY (2015-08-14 - 2015-08-21)
Python tracker at http://bugs.python.org/

To view or respond to any of the issues listed below, click on the issue.
Do NOT respond to this message.

Issues counts and deltas:
  open5013 (+11)
  closed 31656 (+29)
  total  36669 (+40)

Open issues with patches: 2241 


Issues opened (33)
==

#21167: float('nan') returns 0.0 on Python compiled with icc
http://bugs.python.org/issue21167  reopened by r.david.murray

#21192: Idle: Print filename when running a file from editor
http://bugs.python.org/issue21192  reopened by rhettinger

#24869: shlex lineno inaccurate with certain inputs
http://bugs.python.org/issue24869  opened by rescrv

#24870: Optimize coding with surrogateescape and surrogatepass error h
http://bugs.python.org/issue24870  opened by naoki

#24871: freeze.py doesn't work on x86_64 Linux out of the box
http://bugs.python.org/issue24871  opened by termim

#24872: Add /NODEFAULTLIB:MSVCRT to _msvccompiler
http://bugs.python.org/issue24872  opened by steve.dower

#24873: Add "full cleanup" checkbox to uninstaller
http://bugs.python.org/issue24873  opened by steve.dower

#24875: pyvenv doesn´t install PIP inside a new venv with --system-si
http://bugs.python.org/issue24875  opened by gilgamezh

#24876: distutils.errors not wildcard-import-safe
http://bugs.python.org/issue24876  opened by jwilk

#24880: ctypeslib patch for regular expression for symbols to include
http://bugs.python.org/issue24880  opened by jwagner313

#24881: _pyio checks that `os.name == 'win32'` instead of 'nt'
http://bugs.python.org/issue24881  opened by Cosimo Lupo

#24882: ThreadPoolExecutor doesn't reuse threads until #threads == max
http://bugs.python.org/issue24882  opened by Matt Spitz

#24884: Add method reopenFile() in WatchedFileHandler class
http://bugs.python.org/issue24884  opened by Marian Horban

#24885: StreamReaderProtocol docs recommend using private API
http://bugs.python.org/issue24885  opened by aymeric.augustin

#24886: open fails randomly on AIX
http://bugs.python.org/issue24886  opened by wiggin15

#24887: Sqlite3 has no option to provide open flags
http://bugs.python.org/issue24887  opened by sleepycal

#24888: FileNotFoundException raised by subprocess.call
http://bugs.python.org/issue24888  opened by Geoffrey Royer

#24889: Idle: always start with focus
http://bugs.python.org/issue24889  opened by terry.reedy

#24890: Windows launcher docs don't fully explain shebang semantics
http://bugs.python.org/issue24890  opened by BrenBarn

#24891: race condition in initstdio() (python aborts running under noh
http://bugs.python.org/issue24891  opened by Yi Ding

#24893: Tk  occasionally mispositions Text() insert cursor on mouse cl
http://bugs.python.org/issue24893  opened by rhettinger

#24894: iso-8859-11 missing from codecs table
http://bugs.python.org/issue24894  opened by ezio.melotti

#24896: It is undocumented that re.UNICODE affects re.IGNORECASE
http://bugs.python.org/issue24896  opened by Leif Arne Storset

#24898: Documentation for str.find() is confusing
http://bugs.python.org/issue24898  opened by Ted Lemon

#24899: Add an os.path <=> pathlib equivalence table in pathlib docs
http://bugs.python.org/issue24899  opened by ezio.melotti

#24900: Raising an exception that cannot be unpickled causes hang in P
http://bugs.python.org/issue24900  opened by filmor

#24902: http.server: on startup, show host/port as URL
http://bugs.python.org/issue24902  opened by fxkr

#24903: Do not verify destdir argument to compileall
http://bugs.python.org/issue24903  opened by jgarver

#24904: Patch: add timeout to difflib SequenceMatcher ratio() and quic
http://bugs.python.org/issue24904  opened by jftuga

#24905: Allow incremental I/O to blobs in sqlite3
http://bugs.python.org/issue24905  opened by jim_minter

#24906: asyncore asynchat hanging on ssl
http://bugs.python.org/issue24906  opened by Michele Comitini

#24907: Module location load order is not respected if pkg_resources i
http://bugs.python.org/issue24907  opened by Vadim Kantorov

#24908: sysconfig.py and distutils.sysconfig.py disagree on directory 
http://bugs.python.org/issue24908  opened by htnieman



Most recent 15 issues with no replies (15)
==

#24906: asyncore asynchat hanging on ssl
http://bugs.python.org/issue24906

#24905: Allow incremental I/O to blobs in sqlite3
http://bugs.python.org/issue24905

#24899: Add an os.path <=> pathlib equivalence table in pathlib docs
http://bugs.python.org/issue24899

#24894: iso-8859-11 missing from codecs table
http://bugs.python.org/issue24894

#24886: open fails randomly on AIX
http://bugs.python.org/issue24886

#24885: StreamReaderProtocol docs recommend using private API
http://bugs.python.org/issue24885

#24884: Add method reopenFile() in WatchedFileHandler class
http://bugs.python.org/issue24884

#24881: _pyio checks that `os.name == 'win32'` instead of 'nt'
http://bugs.python.org/issue24881

#24876: