[Python-ideas] Re: Resetting peak memory metric in tracemalloc without touching other traces

2020-05-14 Thread Victor Stinner
Hi, The following function is completely reasonable. It shouldn't be hard to implement it (a few lines of C code). def reset_peak_memory(): # in _tracemalloc.c tracemalloc_peak_trace_memory = tracemalloc_traced_memory; Reset the peak to tracemalloc_traced_memory is correct :-

[Python-ideas] Re: Expose _PyGC_generation0 for allowing internal use directly from a CPython extension

2019-10-21 Thread Victor Stinner
He opened https://bugs.python.org/issue38542 It seems like the issue is specific to Python 2.7. Well, see the issue for more details ;-) Victor ___ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@p

[Python-ideas] Re: Expose Py_TabcheckFlag as other PyAPI_DATA flag.

2019-10-21 Thread Victor Stinner
Eloi opened https://bugs.python.org/issue38543 This issue is specific to Python 2.7. Python 3 no longer has Py_TabcheckFlag. Eloi: hey, you should upgrade to Python 3 and have a look at my PEP 587 "Python Initialization Configuration" ;-) Victor ___ Py

[Python-ideas] Re: RFC: PEP xxx: Python Compatibility Version

2019-10-18 Thread Victor Stinner
Hi Ethan, Le ven. 18 oct. 2019 à 04:38, Ethan Furman a écrit : > > To remain relevant and useful, Python has to evolve frequently. Some > > enhancements require incompatible changes. Any incompatible change can > > break an unknown number of Python projects. Developers can decide to > > not impl

[Python-ideas] RFC: PEP xxx: Python Compatibility Version

2019-10-17 Thread Victor Stinner
oming end of Python 2 support, it's the right time to propose this PEP! Victor PEP: xxx Title: Python Compatibility Version Author: Victor Stinner Status: Draft Type: Standards Track Content-Type: text/x-rst Created: 18-Oct-2019 Python-Version: 3.9 Abstract ===

Re: [Python-ideas] Adding str.isascii() ?

2018-01-31 Thread Victor Stinner
I like the idea of str.isdigit(ascii=True): would behave as str.isdigit() and str.isascii(). It's easy to implement and likely to be very efficient. I'm just not sure that it's so commonly required? At least, I guess that some users can be surprised that str.isdigit() is "Unicode aware", accept no

Re: [Python-ideas] Why CPython is still behind in performance for some widely used patterns ?

2018-01-26 Thread Victor Stinner
Hi, Well, I wrote https://faster-cpython.readthedocs.io/ website to answer to such question. See for example https://faster-cpython.readthedocs.io/mutable.html "Everything in Python is mutable". Victor 2018-01-26 22:35 GMT+01:00 Pau Freixes : > Hi, > > This mail is the consequence of a true sto

Re: [Python-ideas] Adding str.isascii() ?

2018-01-26 Thread Victor Stinner
2018-01-26 14:43 GMT+01:00 M.-A. Lemburg : > If that's indeed being used as assumption, the docs must be > fixed and PyUnicode_New() should verify this assumption as > well - not only in debug builds using C asserts() :-) As PyUnicode_FromStringAndSize(NULL, size), PyUnicode_New(size, maxchar) onl

Re: [Python-ideas] Adding str.isascii() ?

2018-01-26 Thread Victor Stinner
2018-01-26 13:39 GMT+01:00 Steven D'Aprano : > I have no objection to isascii, but I don't think it goes far enough. > Sometimes I want to know whether a string is compatible with Latin-1 or > UCS-2 as well as ASCII. For that, I used a function that exposes the > size of code points in bits: Reall

Re: [Python-ideas] Adding str.isascii() ?

2018-01-26 Thread Victor Stinner
2018-01-26 12:17 GMT+01:00 INADA Naoki : >> No, because you can pass in maxchar to PyUnicode_New() and >> the implementation will take this as hint to the max code point >> used in the string. There is no check done whether maxchar >> is indeed the minimum upper bound to the code point ordinals. >

Re: [Python-ideas] Adding str.isascii() ?

2018-01-26 Thread Victor Stinner
+1 The idea is not new and I like it. Naoki created https://bugs.python.org/issue32677 Victor 2018-01-26 11:22 GMT+01:00 Antoine Pitrou : > On Fri, 26 Jan 2018 17:42:31 +0900 > INADA Naoki > wrote: >> >> If str has str.isascii() method, it can be simpler: >> >> `if s.isascii() and s.isdigit():

Re: [Python-ideas] Make functions, methods and descriptor types living in the types module

2018-01-11 Thread Victor Stinner
I like the idea of having a fully qualified name that "works" (can be resolved). I don't think that repr() should change, right? Can this change break the backward compatibility somehow? Victor Le 11 janv. 2018 21:00, "Serhiy Storchaka" a écrit : > Currently the classes of functions (implemen

Re: [Python-ideas] Add an UML class diagram to the collections.abc module documentation

2018-01-01 Thread Victor Stinner
Hi, There is "blockdiag" which is Sphinx friendly: http://blockdiag.com/en/blockdiag/sphinxcontrib.html Look also at: * http://asciiflow.com/ * http://ditaa.sourceforge.net/ * http://asciidoctor.org/news/2014/02/18/plain-text-diagrams-in-asciidoctor/ * etc. I like ASCII Art since it doesn't req

Re: [Python-ideas] Immutable dictionaries

2017-11-29 Thread Victor Stinner
2017-11-29 18:30 GMT+01:00 Asen Bozhilov : > I'd like to propose also literaling syntax for immutable dictionaries. > > immutable_dict = ( > 'key1' : 'value1', > 'key2' : 'value2' > ) Since Python 3.3, you can write: vstinner@apu$ python3 Python 3.6.3 (default, Oct 9 2017, 12:07:10) >>>

Re: [Python-ideas] Should Python have user-defined constants?

2017-11-21 Thread Victor Stinner
2017-11-21 7:33 GMT+01:00 Saeed Baig : > Hey guys I am thinking of perhaps writing a PEP to introduce user-defined > constants to Python. Something along the lines of Swift’s “let” syntax (e.g. > “let pi = 3.14”). If you want to work on a PEP, you will have to write a strong rationale for it :-)

Re: [Python-ideas] Make bytes __repr__ and __str__ representation different?

2017-11-21 Thread Victor Stinner
Hi, While it may shock you, using bytes for "text" makes sense in some areas. Please read the Motivation of the PEP 461: https://www.python.org/dev/peps/pep-0461/#motivation Victor 2017-11-21 15:37 GMT+01:00 Kirill Balunov : > Currently, __repr__ and __str__ representation of bytes is the same.

Re: [Python-ideas] Ignorable whitespaces in the re.VERBOSE mode

2017-11-17 Thread Victor Stinner
I don't think that we need more than space (U+0020) and Unix newline (U+000A) ;-) Victor 2017-11-16 11:23 GMT+01:00 Serhiy Storchaka : > Currently the re module ignores only 6 ASCII whitespaces in the re.VERBOSE > mode: > > U+0009 CHARACTER TABULATION > U+000A LINE FEED > U+000B LI

Re: [Python-ideas] Add time.time_ns(): system clock with nanosecond resolution

2017-10-20 Thread Victor Stinner
Hi francis, Le 20 oct. 2017 18:42, "francismb" a écrit : Hi Victor, On 10/13/2017 04:12 PM, Victor Stinner wrote: > I would like to add: > > * time.time_ns() > * time.monotonic_ns() > * time.perf_counter_ns() > * time.clock_gettime_ns() > * time.clock_se

Re: [Python-ideas] Why not picoseconds?

2017-10-20 Thread Victor Stinner
Antoine Pitrou: > Given the implementation costs, hardware decimal128 will only become > mainstream if there's a strong incentive for it, which I'm not sure > exists or will ever exist ;-) Stefan Behnel: > Then we shouldn't implement the new nanosecond API at all, in order to keep > pressure on th

Re: [Python-ideas] Add time.time_ns(): system clock with nanosecond resolution

2017-10-16 Thread Victor Stinner
2017-10-16 18:13 GMT+02:00 Todd : > I am not suggesting implementing a new numeric data type. People wouldn't > use the class directly like they would an int or float, they would simply > use it to define the the precision and numeric type (float, int, decimal). > Then they would have access to th

Re: [Python-ideas] Add time.time_ns(): system clock with nanosecond resolution

2017-10-16 Thread Victor Stinner
Hi, FYI I proposed the PEP 564 on python-dev. "PEP 564 -- Add new time functions with nanosecond resolution" https://www.python.org/dev/peps/pep-0564/ Victor ___ Python-ideas mailing list Python-ideas@python.org https://mail.python.org/mailman/listinfo

Re: [Python-ideas] Why not picoseconds?

2017-10-16 Thread Victor Stinner
2017-10-16 9:46 GMT+02:00 Stephan Houben : > Hi all, > > I realize this is a bit of a pet peeve of me, since > in my day job I sometimes get people complaining that > numerical data is "off" in the sixteenth significant digit > (i.e. it was stored as a double). > (...) Oh. As usual, I suck at expl

Re: [Python-ideas] Why not picoseconds?

2017-10-16 Thread Victor Stinner
Hi, FYI I proposed the PEP 564 directly on python-dev. The paragraph about "picosecond": https://www.python.org/dev/peps/pep-0564/#sub-nanosecond-resolution Let's move the discussion on python-dev ;-) Victor ___ Python-ideas mailing list Python-ideas

Re: [Python-ideas] Add time.time_ns(): system clock with nanosecond resolution

2017-10-16 Thread Victor Stinner
Hi, > What if we had a class, say time.time_base. The user could specify the base > units (such as "s", "ns", 1e-7, etc) and the data type ('float', 'int', > 'decimal', etc.) when the class is initialized. (...) It's easy to invent various funny new types for arbitrary precision. But I prefer r

Re: [Python-ideas] Add time.time_ns(): system clock with nanosecond resolution

2017-10-16 Thread Victor Stinner
2017-10-16 3:19 GMT+02:00 Juancarlo Añez : > It could be: time.time(ns=True) Please read my initial message: """ [PEP 410] was rejected for different reasons: (...) * Guido van Rossum rejected the idea of adding a new optional parameter to change the result type: it's an uncommon programming pr

Re: [Python-ideas] Why not picoseconds?

2017-10-15 Thread Victor Stinner
'd like to be future-proof, why not > move to picoseconds? That would be safe until clocks reach the THz > barrier, which is quite far away from us. > > Regards > > Antoine. > > > On Fri, 13 Oct 2017 16:12:39 +0200 > Victor Stinner > wrote: > >

Re: [Python-ideas] Add time.time_ns(): system clock with nanosecond resolution

2017-10-15 Thread Victor Stinner
> Might it make more sense to have a parallel *module* that works with a different base data type rather than parallel functions within the existing API? I asked about adding new functions to 4 different modules: os, resource, signal, time. For example, I dislike the idea of having os and os_ns m

Re: [Python-ideas] Add time.time_ns(): system clock with nanosecond resolution

2017-10-15 Thread Victor Stinner
> (That being said, I'm a big fan of fractions, so I wonder if a Fraction with a constant nano denominator wouldn't fit in here...) It was discussed in depth in PEP 410, and the PEP was rejected. Guido voted for nanoseconds as int, when os.stat_result.st_mtime_ns was added. Victor ___

Re: [Python-ideas] Add time.time_ns(): system clock with nanosecond resolution

2017-10-13 Thread Victor Stinner
2017-10-13 16:57 GMT+02:00 Stefan Behnel : > I might have missed it while skipping through your post, but could you > quickly explain why improving the precision of time.time() itself wouldn't > help already? Would double FP precision not be accurate enough here? 80-bit binary float ("long double"

[Python-ideas] Add time.time_ns(): system clock with nanosecond resolution

2017-10-13 Thread Victor Stinner
Hi, I would like to add new functions to return time as a number of nanosecond (Python int), especially time.time_ns(). It would enhance the time.time() clock resolution. In my experience, it decreases the minimum non-zero delta between two clock by 3 times, new "ns" clock versus current clock: 8

Re: [Python-ideas] PEP 560 (second post)

2017-09-29 Thread Victor Stinner
> Title: Core support for generic types Would it be possible to mention "typing" somewhere in the title? If you don't know the context, it's hard to understand that the PEP is related to type annotation and type checks. At least just from the title. Victor

Re: [Python-ideas] Changes to the existing optimization levels

2017-09-28 Thread Victor Stinner
> 2) Added a new command line option N that allows you to specify > any number of individual optimization flags. > > For example: > > python -N nodebug -N noassert -N nodocstring You may want to look at my PEP 511 which proposes to add a new "-o" option to specify a list of optimiz

Re: [Python-ideas] Hexadecimal floating literals

2017-09-21 Thread Victor Stinner
2017-09-21 3:53 GMT+02:00 Steven D'Aprano : > float.fromhex(s) if s.startswith('0x') else float(s) My vote is now -1 on extending the Python syntax to add hexadecimal floating literals. While I was first in favor of extending the Python syntax, I changed my mind. Float constants written in hexade

Re: [Python-ideas] Move some regrtest or test.support features into unittest?

2017-09-19 Thread Victor Stinner
>> * --timeout: watchdog killing the test if the run time exceed the >> timeout in seconds (use faulthandler.dump_traceback_later) > > This feature looks functionally similar to limiting memory usage. Hum, I don't think so. Limiting the memory usage doesn't catch deadlocks for example. Victor ___

Re: [Python-ideas] Move some regrtest or test.support features into unittest?

2017-09-18 Thread Victor Stinner
Antoine: >> * skip a test if it allocates too much memory, command line argument >> to specify how many memory a test is allowed to allocate (ex: >> --memlimit=2G for 2 GB of memory) > > That would be suitable for a plugin if unittest had a plugin > architecture, but not as a core functionality IMO

Re: [Python-ideas] sys.py

2017-09-14 Thread Victor Stinner
Le 14 sept. 2017 01:01, "Eric Snow" a écrit : In the case of sys.modules, the problem is that assigning a bogus value (e.g. []) can cause the interpreter to crash. It wasn't a problem until recently when I removed PyInterpreterState.modules and made sys.modules authoritative (see https://bugs.py

[Python-ideas] Move some regrtest or test.support features into unittest?

2017-09-13 Thread Victor Stinner
Hi, tl; dr How can we extend unittest module to plug new checks before/after running tests? The CPython project has a big test suite in the Lib/test/ directory. While all tests are written with the unittest module and the unittest.TestCase class, tests are not run directly by unittest, but run b

Re: [Python-ideas] Hexadecimal floating literals

2017-09-12 Thread Victor Stinner
2017-09-12 1:27 GMT+02:00 Neil Schemenauer : >> k = float("0x1.2492492492492p-3") # 1/7 > > Making it a different function from float() would avoid backwards > compatibility issues. I.e. float() no longer returns errors on some > inputs. In that case, I suggest float.fromhex() to remain consistent

Re: [Python-ideas] Hexadecimal floating literals

2017-09-12 Thread Victor Stinner
2017-09-12 3:48 GMT+02:00 Steven D'Aprano : >> k = float("0x1.2492492492492p-3") # 1/7 > > Why wouldn't you just write 1/7? 1/7 is irrational, so it's not easy to get the "exact value" for a 64-bit IEEE 754 double float. I chose it because it's easy to write. Maybe math.pi is a better example :-)

Re: [Python-ideas] Hexadecimal floating literals

2017-09-11 Thread Victor Stinner
Instead of modifying the Python grammar, the alternative is to enhance float(str) to support it: k = float("0x1.2492492492492p-3") # 1/7 Victor 2017-09-08 8:57 GMT+02:00 Serhiy Storchaka : > The support of hexadecimal floating literals (like 0xC.68p+2) is included in > just released C++17 standa

Re: [Python-ideas] Hexadecimal floating literals

2017-09-08 Thread Victor Stinner
2017-09-07 23:57 GMT-07:00 Serhiy Storchaka : > The support of hexadecimal floating literals (like 0xC.68p+2) is included in > just released C++17 standard. Seems this becomes a mainstream. Floating literal using base 2 (or base 2^n, like hexadecimal, 2^4) is the only way to get exact values in a

Re: [Python-ideas] Adding "View Python 3 Documentation" to all Python 2 documentation URLs

2017-09-06 Thread Victor Stinner
Another example is PyPI showing a bold "Latest version: x.x.x". Example: https://pypi.python.org/pypi/requests/2.17.0 Victor 2017-09-07 0:52 GMT+02:00 Ryan Gonzalez : > Right now, many Google searches for Python modules return the Python 2 > documentation. IMO since 2 will be reaching EOL in arou

Re: [Python-ideas] Pseudo methods

2017-08-07 Thread Victor Stinner
Ruby provides this feature. A friend who is a long term user of Rails complained that Rails abuses this and it's a mess in practice. So I dislike this idea. Victor 2017-08-04 9:39 GMT+02:00 Paul Laos : > Hi folks > I was thinking about how sometimes, a function sometimes acts on classes, > and >

Re: [Python-ideas] Fwd: Consider allowing the use of abstractmethod without metaclasses

2017-07-20 Thread Victor Stinner
Le 20 juil. 2017 3:49 AM, "INADA Naoki" a écrit : > I'm +1 with your idea in performance point of view. (...) But ABC is too heavy to use only for checking abstract methods. It uses three inefficient WeakSet [1] and it overrides isinstance and issubclass with slow Python implementation. I don't

Re: [Python-ideas] namedtuple literals [Was: RE a new namedtuple]

2017-07-20 Thread Victor Stinner
For me, namedtuple was first used to upgrade an old API from returning a tuple to a "named" tuple. There was a hard requirement on backward compatibility: namedtuple API is a superset of the tuple API. For new code, there is no such backward compatibility issue. If you don't need a type, types.Nam

Re: [Python-ideas] Alternative Unicode implementations (NSString/NSMutableString)

2017-07-19 Thread Victor Stinner
2017-07-19 4:34 GMT+02:00 Nick Coghlan : > 2. Indicate that it's a "lazily rendered" subclass that should hold > off on calling PyUnicode_Ready for as long as possible, but still do > so when necessary (akin to creating strings via the old Py_UNICODE > APIs and then calling PyUnicode_READY on them)

Re: [Python-ideas] Alternative Unicode implementations (NSString/NSMutableString)

2017-07-18 Thread Victor Stinner
Supporting a new kind of string storage would require a lot of efforts. There are a lot of C code specialized for each Unicode kind Victor Le 19 juil. 2017 12:43 AM, "Jim J. Jewett" a écrit : > Ronald Oussoren came up with a concrete use case for wanting the > interpreter to consider something

Re: [Python-ideas] PEP: Hide implementation details in the C API

2017-07-13 Thread Victor Stinner
2017-07-13 15:21 GMT+02:00 Nick Coghlan : > As far as I know, this isn't really why folks find the stable ABI hard > to switch to. Rather, I believe it's because switching to the stable > ABI means completely changing how you define classes to be closer to > the way you define them from Python code

Re: [Python-ideas] PEP: Hide implementation details in the C API

2017-07-13 Thread Victor Stinner
2017-07-12 20:51 GMT+02:00 Brett Cannon : > I also think the motivation doesn't have to be performance but simply > cleaning up how we expose our C APIs to users as shown by the fact we have > messed up the stable API by making it opt-out instead of opt-in. It's hard to sell a "cleanup" to users w

Re: [Python-ideas] PEP: Hide implementation details in the C API

2017-07-13 Thread Victor Stinner
2017-07-13 0:23 GMT+02:00 Stefan Behnel : > From a Cython perspective, it's (not great but) ok if these "implementation > details" were moved somewhere else, but it would be a problem if they > became entirely unavailable for external modules. Cython uses some of the > internals for performance rea

Re: [Python-ideas] PEP: Hide implementation details in the C API

2017-07-11 Thread Victor Stinner
> Step 3: first pass of implementation detail removal > --- > > Modify the ``python`` API: > > * Add a new ``API`` subdirectory in the Python source code which will > "implement" the Python C API > * Replace macros with functions. The implementation

[Python-ideas] PEP: Hide implementation details in the C API

2017-07-11 Thread Victor Stinner
master/2017-PyconUS/summit.pdf Since this is really the first draft, I didn't assign a PEP number to it yet. I prefer to wait for a first feedback round. Victor PEP: xxx Title: Hide implementation details in the C API Version: $Revision$ Last-Modified: $Date$ Author: Victor Stinner , Status:

Re: [Python-ideas] Bytecode JIT

2017-07-03 Thread Victor Stinner
2017-07-02 14:13 GMT+02:00 Steven D'Aprano : > That only solves the problem of mysum being modified, not whether the > arguments are ints. You still need to know whether it is safe to call > some low-level (fast) integer addition routine, or whether you have to > go through the (slow) high-level Py

Re: [Python-ideas] Bytecode JIT

2017-07-01 Thread Victor Stinner
Let's say that you have a function "def mysum (x; y): return x+y", do you always want to use your new IADD instruction here? What if I call mysum ("a", "b")? Victor ___ Python-ideas mailing list Python-ideas@python.org https://mail.python.org/mailman/lis

Re: [Python-ideas] Bytecode JIT

2017-06-30 Thread Victor Stinner
2017-06-30 17:09 GMT+02:00 Soni L. : > CPython should get a tracing JIT that turns slow bytecode into fast > bytecode. > > A JIT doesn't have to produce machine code. bytecode-to-bytecode compilation > is still compilation. bytecode-to-bytecode compilation works on iOS, and > doesn't require deviat

Re: [Python-ideas] Python 4: Concatenation

2017-06-30 Thread Victor Stinner
2017-06-30 1:33 GMT+02:00 Soni L. : > Step 3. add decimal concatenation operator for numbers: 2 cat 3 == 23, 22 > cat 33 = 2233, etc. if you need bitwise concatenation, you're already in > bitwise "hack" land so do it yourself. (no idea why bitwise is considered > hacky as I use it all the time, bu

Re: [Python-ideas] socket module: plain stuples vs named tuples

2017-06-20 Thread Victor Stinner
2017-06-20 4:05 GMT+02:00 INADA Naoki : > Namedtuple in Python make startup time slow. > So I'm very conservative to convert tuple to namedtuple in Python. > INADA Naoki While we are talking about startup time, I would be curious of seeing the overhead (python startup time, when importing socket

Re: [Python-ideas] socket module: plain stuples vs named tuples

2017-06-19 Thread Victor Stinner
; (First open an issue stating that you're interested; point to this email > from me to prevent that some other core dev just closes it again.) > > On Mon, Jun 19, 2017 at 2:24 PM, Victor Stinner > wrote: > >> Hi, >> >> 2017-06-13 22:13 GMT+02:00 Thomas Gü

Re: [Python-ideas] socket module: plain stuples vs named tuples

2017-06-19 Thread Victor Stinner
Hi, 2017-06-13 22:13 GMT+02:00 Thomas Güttler : > AFAIK the socket module returns plain tuples in Python3: > > https://docs.python.org/3/library/socket.html > > Why not use named tuples? For technical reasons: the socket module is mostly implemented in the C language, and define a "named tuple"

Re: [Python-ideas] Dictionary destructing and unpacking.

2017-06-07 Thread Victor Stinner
> In python 3.6+ this is better since the dictionary is insertion-ordered, but is still not really what one would probably want. Be careful: ordered dict is an implementation detail. You must use explicitly collections.OrderedDict() to avoid bad surprises. In CPython 3.7, dict might change again.

Re: [Python-ideas] Security: remove "." from sys.path?

2017-06-05 Thread Victor Stinner
Le 5 juin 2017 00:52, "Guido van Rossum" a écrit : I really don't want people to start using the "from . import foo" idiom for their first steps into programming. It seems a reasonable "defensive programming" maneuver to put in scripts and apps made by professional Python programmers for surpris

Re: [Python-ideas] Security: remove "." from sys.path?

2017-06-02 Thread Victor Stinner
2017-06-02 9:12 GMT+02:00 Greg Ewing : > Why do you want to change it? To make Python more secure. To prevent untrusted modules hijacking stdlib modules on purpose to inject code for example. Victor ___ Python-ideas mailing list Python-ideas@python.org

Re: [Python-ideas] Security: remove "." from sys.path?

2017-06-01 Thread Victor Stinner
> (AIUI, the *current directory* is never on Python's path, but the *script directory* is. They're the same thing a lot of the time.) Oh, it's very common that I run a script from its directory, so yeah script directory = current directory on such case. Sorry for the confusion. You are right, it's

[Python-ideas] Security: remove "." from sys.path?

2017-06-01 Thread Victor Stinner
Hi, Perl 5.26 succeeded to remove the current working directory from the default include path (our Python sys.path): https://metacpan.org/pod/release/XSAWYERX/perl-5.26.0/pod/perldelta.pod#Removal-of-the-current-directory-(%22.%22)-from-@INC Would it technically possible to make this change in P

Re: [Python-ideas] SealedMock proposal for unittest.mock

2017-06-01 Thread Victor Stinner
A stricter mock object cannot be a bad idea :-) I am not sure about your proposed API: some random code may already use this attribute. Maybe it can be a seal (mock) function which sets a secret attribute with a less common name? Yeah, please open an issue on bugs.python.org ;-) Victor Le 29 ma

Re: [Python-ideas] π = math.pi

2017-06-01 Thread Victor Stinner
2017-06-01 8:47 GMT+02:00 Serhiy Storchaka : > What you are think about adding Unicode aliases for some mathematic names in > the math module? ;-) > > math.π = math.pi How do you write π (pi) with a keyboard on Windows, Linux or macOS? Victor ___ Python

Re: [Python-ideas] Add a .chunks() method to sequences

2017-05-04 Thread Victor Stinner
2017-05-05 0:20 GMT+02:00 Greg Ewing : > While most uses would probably be for short strings, I can > think of uses cases involving large ones. For example, to > format a hex dump into lines with 8 bytes per line and spaces > between the lines: For such specialized use case, write a C extension.

Re: [Python-ideas] Add a .chunks() method to sequences

2017-05-04 Thread Victor Stinner
> How about adding a chunks() and rchunks() function to sequences: > > [1,2,3,4,5,6,7].chunks(3) => [[1,2,3], [4,5,6], [7]] I prefer str.join() approach: write a single chunks() function which takes a sequence, instead of modifying all sequence types around the world ;-) It's less natural to writ

Re: [Python-ideas] Thread-safe generators

2017-04-16 Thread Victor Stinner
Thread safety is very complex and has an impact on performance. I dislike the idea of providing such property to generators which can have a complex next method. IMHO it's better to put a generator in wrapper which adds thread safety. What do you think? Victor Le 14 avr. 2017 18:48, "Serhiy Sto

Re: [Python-ideas] Add pathlib.Path.write_json and pathlib.Path.read_json

2017-03-27 Thread Victor Stinner
2017-03-27 17:04 GMT+02:00 Steven D'Aprano : > Of course pathlib can already read JSON, or for that matter ReST text > or JPG binary files. It can read anything as text or bytes, including > JSON: > > some_path.write_text(json.dumps(obj)) > json.loads(some_path.read_text()) Note: You should specif

Re: [Python-ideas] Adding an 'errors' argument to print

2017-03-26 Thread Victor Stinner
unction as shown in a previous email. Victor Le 25 mars 2017 8:50 PM, "Michel Desmoulin" a écrit : Le 24/03/2017 à 17:37, Victor Stinner a écrit : > *If* we change something, I would prefer to modify sys.stdout. The > following issue proposes to add > sys.stdout.set_encod

Re: [Python-ideas] Adding an 'errors' argument to print

2017-03-24 Thread Victor Stinner
*If* we change something, I would prefer to modify sys.stdout. The following issue proposes to add sys.stdout.set_encoding(errors='replace'): http://bugs.python.org/issue15216 You can already set the PYTHONIOENCODING environment variable to ":replace" to use "replace" on sys.stdout (and sys.stderr

Re: [Python-ideas] PEP: Python Documentation Translations

2017-03-23 Thread Victor Stinner
2017-03-22 2:14 GMT+01:00 Victor Stinner : >> Python documentation GitHub organization: https://github.com/python-docs/ > > I tried to create a team in the GitHub Python organization. It works. > But then I don't have the right to add new members, since "I'm not an &

Re: [Python-ideas] PEP: Python Documentation Translations

2017-03-21 Thread Victor Stinner
> Contributor Agreement > ' > > Contributions to translated documentation will be requested to sign the > Python Contributor Agreement (CLA): > > https://www.python.org/psf/contrib/contrib-form/ I'm not sure about this requirement, but I'm not a lawyer. I guess that in case of

Re: [Python-ideas] PEP: Python Documentation Translations

2017-03-21 Thread Victor Stinner
> Python documentation GitHub organization: https://github.com/python-docs/ I tried to create a team in the GitHub Python organization. It works. But then I don't have the right to add new members, since "I'm not an organization owner". IMHO the Python organization is too strict for such translati

Re: [Python-ideas] PEP: Python Documentation Translations

2017-03-21 Thread Victor Stinner
I assigned the number 545 to the PEP. It should be online in less than 2 hours (I don't know what and how PEPs are rendered on python.org) at: https://www.python.org/dev/peps/pep-0545/ Victor ___ Python-ideas mailing list Python-ideas@python.org https://

Re: [Python-ideas] Add socket utilities for IPv4/6 dual-stack servers

2017-03-05 Thread Victor Stinner
Would it be possible to create a PyPI project to experiement the API and wait until we collected enough user feedback first? Currently socket is low level. Not sure if I like the idea of putting more high level features in it? Asyncio is a good place for high level features, but is limited to asyn

Re: [Python-ideas] Optional parameters without default value

2017-03-03 Thread Victor Stinner
Since yet another sentinel singleton sounds like a dead end, I suggest to use [arg=value] syntax and require a default value in the prototype, as currently required for *optional keyword* arguments. "[...]" syntax for optional parameter is commonly used in Python documentation (but the exact synta

Re: [Python-ideas] Optional parameters without default value

2017-03-03 Thread Victor Stinner
2017-03-03 6:13 GMT+01:00 Mike Miller : > Agreed, I've rarely found a need for a "second None" or sentinel either, but > once every few years I do. So, this use case doesn't seem to be common > enough to devote special syntax or a keyword to from my perspective. The question here is how to have a

Re: [Python-ideas] Positional-only parameters

2017-03-02 Thread Victor Stinner
writing it, Victor, or is someone else going to write > it? > > On Tue, 28 Feb 2017 at 13:18 Victor Stinner > wrote: > >> Hi, >> >> For technical reasons, many functions of the Python standard libraries >> implemented in C have positional-only parameter

Re: [Python-ideas] Optional parameters without default value

2017-03-02 Thread Victor Stinner
In my code, I commonly use a NOT_SET singleton used as default value. I like this name for the test: if arg is NOT_SET: ... ;-) I use that when I want to behave differently when None is passed. And yes, I have such code. Victor Le 2 mars 2017 9:36 AM, "M.-A. Lemburg" a écrit : On 02.03.2017

Re: [Python-ideas] Optional parameters without default value

2017-03-02 Thread Victor Stinner
I dislike the try/except NameError test to chevk if the parameter is set. Catching NameError is slow. What is the root issue? Function signature in help(func)? If yes, the solution can be a special value understood by inspect.signature(). Should it be possible to pass explicitly the special value

Re: [Python-ideas] Positional-only parameters

2017-03-02 Thread Victor Stinner
2017-03-02 14:23 GMT+01:00 Steven D'Aprano : >> Replace "replace(self, old, new, count=-1, /)" with "replace(self, >> old, new[, count=-1])" (or maybe even not document the default >> value?). > > That isn't right. It would have to be: > > replace([self, old, new, count=-1]) > > if all of the argum

Re: [Python-ideas] Positional-only parameters

2017-03-02 Thread Victor Stinner
2017-03-01 21:52 GMT+01:00 Terry Reedy : > + 1 also. When people write a Python equivalent of a built-in function for > documentation or teaching purposes, they should be able to exactly mimic the > API. Yeah, Serhiy said basically the same thing: it's doable, but complex without builtin support f

Re: [Python-ideas] Expose a child factory using MappingProxyType in builtins

2017-02-28 Thread Victor Stinner
2017-02-28 13:17 GMT+01:00 Michel Desmoulin : > We have the immutable frozenset for sets and and tuples for lists. > > But we also have something to manipulate dict as immutable datastructures: > from types import MappingProxyType as idict d = idict({'a':1, 'b':2, 'c':3}) d['a'] = 4

[Python-ideas] Positional-only parameters

2017-02-28 Thread Victor Stinner
Hi, For technical reasons, many functions of the Python standard libraries implemented in C have positional-only parameters. Example: --- $ ./python Python 3.7.0a0 (default, Feb 25 2017, 04:30:32) >>> help(str.replace) replace(self, old, new, count=-1, /) # <== notice "/" at the end ...

Re: [Python-ideas] Efficient debug logging

2017-02-16 Thread Victor Stinner
2017-02-16 13:55 GMT+01:00 M.-A. Lemburg : > 1. you don't need a preprocessor for this: simply put your > logging code into an "if __debug__:" block: The problem with -O is that it also disables assertions, whereas you may want to keep them at runtime on production for good reasons. Victor _

Re: [Python-ideas] Efficient debug logging

2017-02-16 Thread Victor Stinner
Yeah, I had a similar issue in a previous company. A colleague wrote a script using a regex to remove these debug logs in the .py code. IHMO the clean design for that would be to support officially preprocessors in Python. My PEP opens the gate for that: https://www.python.org/dev/peps/pep-0511/

[Python-ideas] Is it Python 3 yet? Results on my poll on Twitter

2017-02-07 Thread Victor Stinner
Hi, I created the following poll on Twitter with a duration of 7 days: """ Is it Python 3 yet? https://mail.python.org/pipermail/python-ideas/2017-January/01.html I proposed to hide Python 2 by default from the http://python.org download page. ( ) It's Python 3 O'Clock! ( ) Have some legacy p

Re: [Python-ideas] Is it Python 3 yet?

2017-01-26 Thread Victor Stinner
2017-01-26 17:21 GMT+01:00 Paul Moore : > On a similar note, I always get caught out by the fact that the > Windows default download is the 32-bit version. Are we not yet at a > point where a sufficient majority of users have 64-bit machines, and > 32-bit should be seen as a "specialist" choice? A

Re: [Python-ideas] Is it Python 3 yet?

2017-01-26 Thread Victor Stinner
If you only want to vote +1 or -1 with no rationale, you may prefer to vote on my Twitter poll: https://twitter.com/VictorStinner/status/824654597235040257 Otherwise, please explain a little bit. Victor ___ Python-ideas mailing list Python-ideas@python.

[Python-ideas] Is it Python 3 yet?

2017-01-26 Thread Victor Stinner
Hi, The download button of https://www.python.org/ currently gives the choice between Python 2.7 and 3.6. I read more and more articles saying that we reached a point where Python 3 became more popular than Python 2, Python 3 has now enough new features to convince developers, etc. Is it time to

Re: [Python-ideas] Fused multiply-add (FMA)

2017-01-16 Thread Victor Stinner
2017-01-15 18:25 GMT+01:00 Juraj Sukop : > C99 includes `fma` function to `math.h` [6] and emulates the calculation if > the FMA instruction is not present on the host CPU [7]. If even the libc function has a fallback on x*y followed by +z, it's fine to add such function to the Python stdlib. It m

Re: [Python-ideas] RFC: PEP 540 version 3 (Add a new UTF-8 mode)

2017-01-12 Thread Victor Stinner
2017-01-12 17:10 GMT+01:00 Oleg Broytman : >> Does it work to use a locale with encoding A for LC_CTYPE and a locale >> with encoding B for LC_MESSAGES (and others)? Is there a risk of > >It does when B is a subset of A (ascii and koi8; ascii and utf8, e.g.) My question is more when A and B en

Re: [Python-ideas] RFC: PEP 540 version 3 (Add a new UTF-8 mode)

2017-01-12 Thread Victor Stinner
2017-01-12 9:45 GMT+01:00 INADA Naoki : > When using en_US.UTF-8 as fallback, pleas override only LC_CTYPE, > instead of LC_ALL. > As I described in other thread, LC_COLLATE may cause unintentional performance > regression and behavior changes. Does it work to use a locale with encoding A for LC_C

Re: [Python-ideas] Settable defaulting to decimal instead of float

2017-01-12 Thread Victor Stinner
2017-01-12 13:13 GMT+01:00 Stephan Houben : > Something like: > from __syntax__ import decimal_literal IMHO you can already implement that with a third party library, see for example: https://github.com/lihaoyi/macropy It also reminds me my PEP 511 which would open the gate for any kind of Python

Re: [Python-ideas] RFC: PEP 540 version 3 (Add a new UTF-8 mode)

2017-01-12 Thread Victor Stinner
2017-01-12 9:45 GMT+01:00 INADA Naoki : > As I described in other thread, LC_COLLATE may cause unintentional performance > regression and behavior changes. Since Python 3 uses mostly text, not bytes, LC_COLLATE should not really impact Python applications. Locales set by setlocale() are not inheri

Re: [Python-ideas] PEP 540: Add a new UTF-8 mode

2017-01-12 Thread Victor Stinner
2017-01-12 1:23 GMT+01:00 INADA Naoki : > I'm ±0 to surrogateescape by default. I feel +1 for stdout and -1 for stdin. The use case is to be able to write a Python 3 program which works work UNIX pipes without failing with encoding errors: https://www.python.org/dev/peps/pep-0540/#producer-consum

Re: [Python-ideas] Settable defaulting to decimal instead of float

2017-01-12 Thread Victor Stinner
George requested this feature on the bug tracker: http://bugs.python.org/issue29223 George was asked to start a discusson on this list. I posted the following comment before closing the issue: You are not the first one to propose the idea. 2012: "make decimal the default non-integer instead of f

Re: [Python-ideas] PEP 540: Add a new UTF-8 mode

2017-01-11 Thread Victor Stinner
2017-01-06 10:50 GMT+01:00 M.-A. Lemburg : > Victor: I think you are taking the UTF-8 idea a bit too far. > Nick was trying to address the situation where the locale is > set to "C", or rather not set at all (in which case the lib C > defaults to the "C" locale). The latter is a fairly standard > s

  1   2   >