Re: [Python-Dev] PEP 455: TransformDict

2013-09-13 Thread Steven D'Aprano
On Fri, Sep 13, 2013 at 06:00:18PM -0700, Ethan Furman wrote: Personally, if there's a bunch of push-back against just adding TransformDict directly, why don't we make it provisional? I thought that was what provisional was for (meaning: we're going to add it, PyPI is not really

Re: [Python-Dev] PEP 455: TransformDict

2013-09-13 Thread Steven D'Aprano
On Sat, Sep 14, 2013 at 02:25:42AM +0100, MRAB wrote: On 14/09/2013 01:49, Steven D'Aprano wrote: d = TransformDict(...) for key in data: key = d.get_canonical(key) value = d[key] print({}: {}.format(key, value)) I think must be missing something. I thought that iterating

Re: [Python-Dev] PEP 455: TransformDict

2013-09-13 Thread Steven D'Aprano
On Fri, Sep 13, 2013 at 06:00:18PM -0700, Ethan Furman wrote: On 09/13/2013 05:49 PM, Steven D'Aprano wrote: +1 on __transform__ method on dicts. What would __transform__ do? Just canonicalize the key, or also save the original key? How much front-end work will each user have to do

Re: [Python-Dev] PEP 455: TransformDict

2013-09-13 Thread Steven D'Aprano
On Fri, Sep 13, 2013 at 06:40:06PM -0700, Ethan Furman wrote: and if you wanted the transformed key you would apply the transform function to the key. Indeed. The question is: how? It is entirely possible that your function has a TransformDict alone, and no memory of the transform

Re: [Python-Dev] PEP 450 adding statistics module

2013-09-16 Thread Steven D'Aprano
statistics.rst file. I don't recall any other outstanding issues, if I have forgotten any, please remind me. On Fri, Sep 13, 2013 at 5:59 PM, Steven D'Aprano st...@pearwood.infowrote: On Sun, Sep 08, 2013 at 10:51:57AM -0700, Guido van Rossum wrote: Never mind, I found the patch and the issue. I

Re: [Python-Dev] PEP 450 adding statistics module

2013-09-17 Thread Steven D'Aprano
On Tue, Sep 17, 2013 at 02:21:16PM -0700, Guido van Rossum wrote: Congrats, I've accepted the PEP. Nice work! Please work with the reviewers on the issue on the code. Thank you, and thanks to everyone who contributed with the discussion. (Steven or Oscar, if either of you could work Oscar's

Re: [Python-Dev] Use an empty def as a lambda

2013-09-19 Thread Steven D'Aprano
On Thu, Sep 19, 2013 at 01:54:08PM -0700, Ben Gift wrote: I think the lambda keyword is difficult to understand for many people. It would be more pythonic to use an empty def call instead. Hi Ben, and welcome! Is this your first post? I'm afraid I don't recognise your name. I think this

Re: [Python-Dev] Use an empty def as a lambda

2013-09-21 Thread Steven D'Aprano
Guys, this thread is not Python-Dev territory. It should have gone to Python-Ideas. I repeat what I posted two days ago: Proposals for changes to syntax and functionality are normally expected to gather feedback on python-ideas before coming to python-dev for final approval or

[Python-Dev] Best practice for documentation for std lib

2013-09-21 Thread Steven D'Aprano
Hi all, I have a question about how I should manage documentation for the statistics module for Python 3.4. At the moment, I have extensive docstrings in the module itself. I don't believe anyone has flagged that as too much information in a code review, so I'm going to assume that large

Re: [Python-Dev] Best practice for documentation for std lib

2013-09-22 Thread Steven D'Aprano
On Sun, Sep 22, 2013 at 10:20:46AM +0200, Antoine Pitrou wrote: On Sun, 22 Sep 2013 13:13:04 +1000 Steven D'Aprano st...@pearwood.info wrote: Hi all, I have a question about how I should manage documentation for the statistics module for Python 3.4. At the moment, I have extensive

Re: [Python-Dev] Best practice for documentation for std lib

2013-09-22 Thread Steven D'Aprano
On Sun, Sep 22, 2013 at 05:54:57AM -0700, Eli Bendersky wrote: IMHO the right way to think about it is that the .rst files are by far the more important documentation. Sometimes we forget that most Python programmers are people who won't go into the source to read docstrings. Docstrings are

Re: [Python-Dev] Best practice for documentation for std lib

2013-09-22 Thread Steven D'Aprano
On Sun, Sep 22, 2013 at 10:07:28AM -0700, Guido van Rossum wrote: Authors writing 3rd party packages can do what they want. But for the stdlib it's been settled for ages: docstrings should be concise (but not cryptic(*)), longer documentation go into the separately written text for

Re: [Python-Dev] Enum Eccentricities

2013-09-23 Thread Steven D'Aprano
On Mon, Sep 23, 2013 at 07:53:00AM -0700, Guido van Rossum wrote: there is no rule that because you can access something on the class you should be able to access it on the instance. Try asking an instance for its class's __mro__ or __bases__. It might not be a rule, but it's certainly the

Re: [Python-Dev] Best practice for documentation for std lib

2013-09-23 Thread Steven D'Aprano
This is getting off-topic, if you're not interested in English grammar you should stop reading. On Mon, Sep 23, 2013 at 03:18:01PM -0400, Alexander Belopolsky wrote: I don't think Returns bar. is a valid English sentence because it lacks subject. Subjectless sentences are unusual in

Re: [Python-Dev] Why not support user defined operator overloading ?

2013-09-29 Thread Steven D'Aprano
On Sun, Sep 29, 2013 at 08:51:37PM +0800, 张佩佩 wrote: Hello: As far as I know, there is not a language support user defined operator overloading. Python3 can overloading belowed operators. [...] (Do I miss something ?) Yes, many.

Re: [Python-Dev] Why not support user defined operator overloading ?

2013-09-29 Thread Steven D'Aprano
On Sun, Sep 29, 2013 at 03:35:27PM -0400, Ned Batchelder wrote: It isn't just a matter of a more complex parser: where would the parser get the information about these new operators? The obvious first answer is that they would be defined as part of classes, but that means the operator

Re: [Python-Dev] Make str/bytes hash algorithm pluggable?

2013-10-04 Thread Steven D'Aprano
On Sat, Oct 05, 2013 at 01:27:37AM +0200, Victor Stinner wrote: I have no idea of the price of renting a botnet, it's probably expensive (and illegal as well). Twelve cents per machine. Cheaper in bulk, and cheaper still for machines outside of the US. For those on a budget, you can get ten

Re: [Python-Dev] PEP 455: TransformDict

2013-10-07 Thread Steven D'Aprano
On Fri, Oct 04, 2013 at 11:06:15PM +0200, Victor Stinner wrote: (If we cannot find a better name, we may add more specialized classes: KeyInsensitiveDict and IdentiyDict. But I like the idea of using my own transform function.) -1 on a plethora of specialised dicts. I do think that a

Re: [Python-Dev] PEP 455: TransformDict

2013-10-07 Thread Steven D'Aprano
On Mon, Oct 07, 2013 at 02:55:44PM -0700, Ethan Furman wrote: On 10/07/2013 02:24 PM, Steven D'Aprano wrote: On Fri, Oct 04, 2013 at 11:06:15PM +0200, Victor Stinner wrote: if type(self) is not dict: # This only applies to subclasses, not dict itself. try: transform

Re: [Python-Dev] PEP 455: TransformDict

2013-10-07 Thread Steven D'Aprano
On Mon, Oct 07, 2013 at 06:17:09PM -0700, Mark Janssen wrote: Sorry I missed the original discussion, but isn't this a simple case of putting a decorator around the getitem method (to transform the input key) and a single line in the body of the setitem method, making this very easy adaptation

Re: [Python-Dev] PEP 457: Syntax For Positional-Only Parameters

2013-10-08 Thread Steven D'Aprano
On Wed, Oct 09, 2013 at 01:33:26AM +0200, Larry Hastings wrote: This PEP proposes a syntax for positional-only parameters in Python. Positional-only parameters are parameters without an externally-usable name; when a function accepting positional-only parameters is called, positional

Re: [Python-Dev] type.__subclasses__() doesn't work

2013-10-09 Thread Steven D'Aprano
On Wed, Oct 09, 2013 at 12:20:18PM +0200, Antoine Pitrou wrote: Hello, Just noticed the following quirk: type.__subclasses__() Traceback (most recent call last): File stdin, line 1, in module TypeError: descriptor '__subclasses__' of 'type' object needs an argument Yet it would

Re: [Python-Dev] PEP 457: Syntax For Positional-Only Parameters

2013-10-09 Thread Steven D'Aprano
On Wed, Oct 09, 2013 at 02:25:18PM -0400, Terry Reedy wrote: Unlike Georg, I think '/' is plausibly ok. You should, however, explicitly say in the PEP that it was selected not randomly but by rough analogy. Division (/) is the inverse of multiplication (*), and positional-only is sort of

Re: [Python-Dev] PEP 457: Syntax For Positional-Only Parameters

2013-10-09 Thread Steven D'Aprano
On Wed, Oct 09, 2013 at 09:46:00PM +0100, Mark Shannon wrote: There is no need to create an undefined value. Rather than define a parameter by assigning a fake value, just don't define it. We already do this for non-parameter locals and it could be extended to parameters. 'range' would

Re: [Python-Dev] PEP 457: Syntax For Positional-Only Parameters

2013-10-09 Thread Steven D'Aprano
On Wed, Oct 09, 2013 at 04:15:36PM +0200, Larry Hastings wrote: - parameters in optional groups should just have an implied =None that can be overriden if desired. No no no! You can't have a default value, and you definitely couldn't use None. range() decides what its arguments mean

Re: [Python-Dev] Support keyword in PEP URL?

2013-10-12 Thread Steven D'Aprano
On Sat, Oct 12, 2013 at 10:48:41AM +0100, Paul Moore wrote: On 12 October 2013 01:53, Victor Stinner victor.stin...@gmail.com wrote: t's easy to mix up PEP numbers. For example, Martin von Loewis wrote two major PEP related to Unicode: 383 and 393. These numbers are close, only one digit is

Re: [Python-Dev] non-US zip archives support in zipfile.py

2013-10-15 Thread Steven D'Aprano
On Tue, Oct 15, 2013 at 10:20:03AM +0200, Victor Stinner wrote: Both issues are related and should be fixed in the *same* commit. Python should provide an option to encode explicitly filenames to UTF-8. Or maybe better: encode to UTF-8 by default, with an option to encode to cp437, and another

Re: [Python-Dev] cpython: Rename contextlib.ignored() to contextlib.ignore().

2013-10-15 Thread Steven D'Aprano
On Wed, Oct 16, 2013 at 09:24:11AM +1000, Nick Coghlan wrote: Even though it eventually convinced me to change the name, this thread still epitomises everything that sucks about soul destroying, energy draining bikeshed painting that makes me wonder why I ever bother trying to make anything

Re: [Python-Dev] About 'superobject' and descriptors

2013-10-23 Thread Steven D'Aprano
Hi Hakril, I think this question is probably off-topic for this list. This list is for development of the Python compiler, not for development with Python, and questions like this should probably go to python-l...@python.org (also mirrored as comp.lang.python if you have Usenet access). But I

Re: [Python-Dev] VAX NaN evaluations

2013-11-04 Thread Steven D'Aprano
On Mon, Nov 04, 2013 at 08:47:53PM +, John Klos wrote: [...] The short answer is to skip those tests on VAXen. The better answer is to patch any isnan functions to always return false on VAXen and patch any code which tries to parse, for instance, float(NaN) to use something uncommon,

Re: [Python-Dev] Issue 19332: Guard against changing dict during iteration

2013-11-06 Thread Steven D'Aprano
On Tue, Nov 05, 2013 at 08:38:09PM -0800, Ethan Furman wrote: http://bugs.python.org/issue19332 Duplicate of this: http://bugs.python.org/issue6017 The conclusion on that also was that it is not worth guarding against such an unusual circumstance. -- Steven

Re: [Python-Dev] Avoid formatting an error message on attribute error

2013-11-06 Thread Steven D'Aprano
On Wed, Nov 06, 2013 at 11:32:33PM +0100, Victor Stinner wrote: Hi, I'm trying to avoid unnecessary temporary Unicode strings when possible (see issue #19512). While working on this, I saw that Python likes preparing an user friendly message to explain why getting an attribute failed. The

Re: [Python-Dev] The pysandbox project is broken

2013-11-12 Thread Steven D'Aprano
On Wed, Nov 13, 2013 at 12:58:42AM +0100, Victor Stinner wrote: I now gave up on sandboxing Python. I just would like to warn other core developers that trying to put a sandbox in Python is not a good idea :-) Do you mean CPython? Do you think it would be productive to create an independent

Re: [Python-Dev] unicode Exception messages in py2.7

2013-11-14 Thread Steven D'Aprano
On Thu, Nov 14, 2013 at 04:55:19PM -0500, Tres Seaver wrote: Fixing any bug is changing behavior; 2.7 is not frozen for bugfixes. It's not a given that the current behaviour *is* a bug. Exception messages in 2 are byte-strings, not Unicode. Trying to use Unicode instead is not, as far as I

Re: [Python-Dev] unicode Exception messages in py2.7

2013-11-14 Thread Steven D'Aprano
On Thu, Nov 14, 2013 at 09:09:06PM -0500, Terry Reedy wrote: 1.5 was around for a long time; not sure if it is completely gone yet. It's not. I forget the details, but after the last American PyCon, somebody posted a message about a fellow they met who was still using 1.5 in production. --

Re: [Python-Dev] unicode Exception messages in py2.7

2013-11-14 Thread Steven D'Aprano
On Thu, Nov 14, 2013 at 04:02:17PM -0800, Chris Barker wrote: On Thu, Nov 14, 2013 at 1:55 PM, Tres Seaver tsea...@palladion.com wrote: Fixing any bug is changing behavior; 2.7 is not frozen for bugfixes. Thank you. The real question is whether third-party code will break when the

Re: [Python-Dev] unicode Exception messages in py2.7

2013-11-14 Thread Steven D'Aprano
On Fri, Nov 15, 2013 at 02:28:48PM +1100, Cameron Simpson wrote: Non-ascii Unicode strings are just a special case of the more general problem of what to do if printing the exception raises. If str(exception.message) raises, suppressing the message seems like a perfectly reasonable

Re: [Python-Dev] Add transform() and untranform() methods

2013-11-15 Thread Steven D'Aprano
On Fri, Nov 15, 2013 at 05:13:34PM +1000, Nick Coghlan wrote: A few things I noticed while implementing the recent updates: - as you noted in your other email, while MAL is on record as saying the codecs module is intended for arbitrary codecs, not just Unicode encodings, readers of the

Re: [Python-Dev] Add transform() and untranform() methods

2013-11-15 Thread Steven D'Aprano
On Fri, Nov 15, 2013 at 10:22:28AM +0100, Antoine Pitrou wrote: On Fri, 15 Nov 2013 09:03:37 +1000 Nick Coghlan ncogh...@gmail.com wrote: And add transform() and untransform() methods to bytes and str types. In practice, it might be same codecs registry for all codecs just with a new

Re: [Python-Dev] (#19562) Asserts in Python stdlib code (datetime.py)

2013-11-16 Thread Steven D'Aprano
On Sat, Nov 16, 2013 at 04:46:00PM +0100, Antoine Pitrou wrote: I agree that conflating the two doesn't help the discussion. While removing docstrings may be beneficial on memory-constrained devices, I can't remember a single situation where I've wanted to remove asserts on a production

Re: [Python-Dev] (#19562) Asserts in Python stdlib code (datetime.py)

2013-11-16 Thread Steven D'Aprano
On Sun, Nov 17, 2013 at 01:50:31AM +1000, Nick Coghlan wrote: No, that's the wrong question to ask. The onus is on *you* to ask Who is this feature for? Do they still need it? Can we meet their needs in a different way?. You're the one proposing to break things, so it's up to you to make the

Re: [Python-Dev] (#19562) Asserts in Python stdlib code (datetime.py)

2013-11-16 Thread Steven D'Aprano
On Sat, Nov 16, 2013 at 11:16:48AM -0500, Donald Stufft wrote: Personally I think that none of the -O* should be removing asserts. It feels like a foot gun to me. I’ve seen more than one codebase that would be completely broken under -O* because they used asserts without even knowing -O*

Re: [Python-Dev] (#19562) Asserts in Python stdlib code (datetime.py)

2013-11-17 Thread Steven D'Aprano
On Sun, Nov 17, 2013 at 11:00:50AM +0100, Antoine Pitrou wrote: On Sun, 17 Nov 2013 18:04:43 +1100 Steven D'Aprano st...@pearwood.info wrote: On Sat, Nov 16, 2013 at 04:46:00PM +0100, Antoine Pitrou wrote: I agree that conflating the two doesn't help the discussion. While removing

Re: [Python-Dev] (#19562) Asserts in Python stdlib code (datetime.py)

2013-11-17 Thread Steven D'Aprano
On Sun, Nov 17, 2013 at 11:35:21AM +0100, Antoine Pitrou wrote: You didn't answer my question: did you actually use -OO in production, or not? Saying that -OO could have helped you optimize something you didn't care about isn't a very strong argument for -OO :) Ah, sorry, I misunderstood your

Re: [Python-Dev] Which direction is UnTransform? / Unicode is different

2013-11-20 Thread Steven D'Aprano
On Tue, Nov 19, 2013 at 05:28:48PM -0800, Jim J. Jewett wrote: (Fri Nov 15 16:57:00 CET 2013) Stephen J. Turnbull wrote: Serhiy Storchaka wrote: If the transform() method will be added, I prefer to have only one transformation method and specify a direction by the

Re: [Python-Dev] PEP process entry point and ill fated initiatives

2013-11-29 Thread Steven D'Aprano
On Fri, Nov 29, 2013 at 03:25:14PM +, Kristján Valur Jónsson wrote about the PEP process: How about acknowledging that these waters are dark and murky and help making things better? Well, how about? If Anatoly has a concrete proposal, surely he can propose a patch to make things

Re: [Python-Dev] One-line abstractmethod function?

2013-12-06 Thread Steven D'Aprano
On Fri, Dec 06, 2013 at 07:28:57AM +0100, Gregory Salvan wrote: Hi, maybe a syntax like that can correspond: class MyObject(metaclass=ObjectSpec): ''' MyObject doc''' 'attr1 contains something' attr1 = None 'attr2 contains something' attr2 = str 'method1 do

Re: [Python-Dev] How long the wrong type of argument should we limit (or not) in the error message (C-api)?

2013-12-14 Thread Steven D'Aprano
On Sun, Dec 15, 2013 at 11:25:10AM +1000, Nick Coghlan wrote: Oh, yes, a %T shortcut for length limited type name of the supplied object would be brilliant. We need this frequently for C level error messages, and I almost always have to look at an existing example to remember the exact

Re: [Python-Dev] How long the wrong type of argument should we limit (or not) in the error message (C-api)?

2013-12-15 Thread Steven D'Aprano
On Mon, Dec 16, 2013 at 07:30:56AM +1000, Nick Coghlan wrote: On 16 Dec 2013 02:58, Ethan Furman et...@stoneleaf.us wrote: On 12/14/2013 07:51 PM, Steven D'Aprano wrote: On Sun, Dec 15, 2013 at 11:25:10AM +1000, Nick Coghlan wrote: Oh, yes, a %T shortcut for length limited type name

Re: [Python-Dev] Fwd: Python 2.x and 3.x usage survey

2013-12-31 Thread Steven D'Aprano
On Tue, Dec 31, 2013 at 08:16:33AM +0100, Lennart Regebro wrote: On Tue, Dec 31, 2013 at 6:31 AM, Dan Stromberg drsali...@gmail.com wrote: So far the results are looking good for 3.x. Python-dev probably is a bit special. Why? Most Python-Dev people have day jobs, and the version of Python

Re: [Python-Dev] Python3 complexity

2014-01-09 Thread Steven D'Aprano
On Thu, Jan 09, 2014 at 05:11:06PM +1000, Nick Coghlan wrote: On 9 January 2014 10:07, Ben Finney ben+pyt...@benfinney.id.au wrote: So, if what you want is to parse text and not get gibberish, you need to *tell* Python what the encoding is. That's a brute fact of the world of text in

Re: [Python-Dev] Python3 complexity

2014-01-09 Thread Steven D'Aprano
On Thu, Jan 09, 2014 at 01:00:59PM +, Kristján Valur Jónsson wrote: Which reminds me, can Python3 read text files with BOM automatically yet? I'm not sure what you mean by that. If you mean, can Python3 distinguish between UTF-16BE and UTF-16LE on the basis of a BOM, then it's been able

Re: [Python-Dev] Python3 complexity

2014-01-09 Thread Steven D'Aprano
On Thu, Jan 09, 2014 at 02:08:57PM -0800, Ethan Furman wrote: If latin1 is used to convert binary to text, how convoluted is it to then take chunks of that text and convert to int, or some other variety of unicode? For example: b'\x01\x00\xd1\x80\xd1\83\xd0\x80' If that were decoded

Re: [Python-Dev] Python3 complexity

2014-01-09 Thread Steven D'Aprano
On Fri, Jan 10, 2014 at 12:22:02PM +1100, Chris Angelico wrote: On Fri, Jan 10, 2014 at 11:53 AM, anatoly techtonik techto...@gmail.com wrote: 2. introduce autodetect mode to open functions 1. read and transform on the fly, maintaining a buffer that stores original bytes

Re: [Python-Dev] RFC: PEP 460: Add bytes % args and bytes.format(args) to Python 3.5

2014-01-10 Thread Steven D'Aprano
On Fri, Jan 10, 2014 at 06:17:02PM +0100, Juraj Sukop wrote: As you may know, PDF operates over bytes and an integer or floating-point number is written down as-is, for example 100 or 1.23. I'm sorry, I don't understand what you mean here. I'm honestly not trying to be difficult, but you

Re: [Python-Dev] RFC: PEP 460: Add bytes % args and bytes.format(args) to Python 3.5

2014-01-11 Thread Steven D'Aprano
On Sat, Jan 11, 2014 at 01:56:56PM +0100, Juraj Sukop wrote: On Sat, Jan 11, 2014 at 6:36 AM, Steven D'Aprano st...@pearwood.infowrote: If you consider PDF as binary with occasional pieces of ASCII text, then working with bytes makes sense. But I wonder whether it might be better

Re: [Python-Dev] RFC: PEP 460: Add bytes % args and bytes.format(args) to Python 3.5

2014-01-11 Thread Steven D'Aprano
On Sat, Jan 11, 2014 at 08:20:27AM -0800, Ethan Furman wrote: On 01/11/2014 07:38 AM, Steven D'Aprano wrote: The point that I am making is that many people want to add formatting operations to bytes so they can put ASCII strings inside bytes. But (as far as I can tell) they don't need to do

Re: [Python-Dev] RFC: PEP 460: Add bytes % args and bytes.format(args) to Python 3.5

2014-01-11 Thread Steven D'Aprano
On Sat, Jan 11, 2014 at 04:15:35PM +0100, M.-A. Lemburg wrote: I think we need to step back a little from the purist view of things and give more emphasis on the practicality beats purity Zen. I complete agree with Stephen, that bytes are in fact often an encoding of text. If that text is

Re: [Python-Dev] RFC: PEP 460: Add bytes % args and bytes.format(args) to Python 3.5

2014-01-11 Thread Steven D'Aprano
On Sat, Jan 11, 2014 at 05:33:17PM +0100, M.-A. Lemburg wrote: FWIW: I quite liked the Python 2 model, but perhaps that's because I already knww how Unicode works, so could use it to make my life easier ;-) /incredulous I would really love to see you justify that claim. How do you use the

Re: [Python-Dev] RFC: PEP 460: Add bytes % args and bytes.format(args) to Python 3.5

2014-01-11 Thread Steven D'Aprano
On Sat, Jan 11, 2014 at 07:22:30PM +, MRAB wrote: with open(outfile.pdf, w, encoding=latin-1) as f: f.write(pdf) [snip] The second example won't work because you're forgetting about the handling of line endings in text mode. So I did! Thank you for the correction. -- Steven

Re: [Python-Dev] RFC: PEP 460: Add bytes % args and bytes.format(args) to Python 3.5

2014-01-11 Thread Steven D'Aprano
On Sat, Jan 11, 2014 at 04:28:34PM -0500, Terry Reedy wrote: The problem with some criticisms of using 'unicode in Python 3' is that there really is no such thing. Unicode in 3.0 to 3.2 used the old internal model inherited from 2.x. Unicode in 3.3+ uses a different internal model that is

Re: [Python-Dev] RFC: PEP 460: Add bytes % args and bytes.format(args) to Python 3.5

2014-01-11 Thread Steven D'Aprano
On Sat, Jan 11, 2014 at 08:13:39PM -0200, Mariano Reingart wrote: AFAIK (and just for the record), there could be both Latin1 text and UTF-16 in a PDF (and other encodings too), depending on the font used: [...] In Python2, txt is just a str, but in Python3 handling everything as latin1

Re: [Python-Dev] RFC: PEP 460: Add bytes % args and bytes.format(args) to Python 3.5

2014-01-12 Thread Steven D'Aprano
On Sun, Jan 12, 2014 at 12:52:18PM +0100, Juraj Sukop wrote: On Sun, Jan 12, 2014 at 2:35 AM, Steven D'Aprano st...@pearwood.infowrote: On Sat, Jan 11, 2014 at 08:13:39PM -0200, Mariano Reingart wrote: AFAIK (and just for the record), there could be both Latin1 text and UTF-16

Re: [Python-Dev] RFC: PEP 460: Add bytes % args and bytes.format(args) to Python 3.5

2014-01-12 Thread Steven D'Aprano
On Sun, Jan 12, 2014 at 11:16:37PM +1000, Nick Coghlan wrote: content = '\n'.join([ 'header', 'part 2 %.3f' % number, binary_image_data.decode('latin-1'), utf16_string.encode('utf-16be').decode('latin-1'), 'trailer']).encode('latin-1')

Re: [Python-Dev] RFC: PEP 460: Add bytes % args and bytes.format(args) to Python 3.5

2014-01-12 Thread Steven D'Aprano
On Mon, Jan 13, 2014 at 07:31:16AM +0900, Stephen J. Turnbull wrote: Steven D'Aprano writes: then the name is horribly misleading, and it is best handled like this: content = '\n'.join([ 'header', 'part 2 %.3f' % number, binary_image_data.decode

[Python-Dev] Smuggling bytes into text (was Re: RFC: PEP 460: Add bytes % args and bytes.format(args) to Python 3.5)

2014-01-12 Thread Steven D'Aprano
wrote: On 01/11/2014 06:29 PM, Steven D'Aprano wrote: [...] Since you're talking to me, it would be nice if you addressed the same use-case I was addressing, which is mixed: ascii-encoded text, ascii-encoded numbers, ascii-encoded bools, binary-encoded numbers, and misc-encoded text. I

Re: [Python-Dev] Smuggling bytes into text (was Re: RFC: PEP 460: Add bytes % args and bytes.format(args) to Python 3.5)

2014-01-12 Thread Steven D'Aprano
On Mon, Jan 13, 2014 at 01:03:15PM +1100, Steven D'Aprano wrote: code speaks louder than words: http://www.pearwood.info/ethan_demo.py [...] Ethan refers to code like: template % (срЃ.encode('cp1251').decode('latin-1'), 42, blob.decode('latin-1')) You did say to use a *text* template

Re: [Python-Dev] Automatic encoding detection [was: Re: Python3 complexity - 2 use cases]

2014-01-13 Thread Steven D'Aprano
On Mon, Jan 13, 2014 at 07:58:43PM -0500, Terry Reedy wrote: This discussion strikes me as more appropriate for python-ideas. That said, I am leery of a heuristics module in the stdlib. When is a change a 'bug fix'? and when is it an 'enhancement'? Depends on the nature of the heuristic.

Re: [Python-Dev] magic method __bytes__

2014-01-14 Thread Steven D'Aprano
On Tue, Jan 14, 2014 at 10:58:49AM -0500, R. David Murray wrote: On Mon, 13 Jan 2014 17:38:38 -0800, Ethan Furman et...@stoneleaf.us wrote: Has anyone actually used __bytes__ yet? What for? bytes(email.message.Message()) returns the message object serialized to wire format. --David

Re: [Python-Dev] PEP 460: allowing %d and %f and mojibake

2014-01-14 Thread Steven D'Aprano
On Tue, Jan 14, 2014 at 10:16:17AM -0800, Guido van Rossum wrote: Hm. It is beginning to sound more and more flawed. I also worry that it will bring back the nightmare of data-dependent UnicodeError back. E.g. this (from tests/basic.py): def

Re: [Python-Dev] PEP 460: allowing %d and %f and mojibake

2014-01-14 Thread Steven D'Aprano
On Wed, Jan 15, 2014 at 01:03:13PM +1300, Greg Ewing wrote: Nick Coghlan wrote: That way lies the Python 2 text model, and we're not going there. It's probably best to think of asciistr as a way of demonstrating a rhetorical point about the superiority of the Python 3 text model Hmmm...

Re: [Python-Dev] PEP 461 - Adding % and {} formatting to bytes

2014-01-15 Thread Steven D'Aprano
On Thu, Jan 16, 2014 at 10:55:31AM +1300, Greg Ewing wrote: Neil Schemenauer wrote: Objects that implement __str__ can also implement __bytes__ if they can guarantee that ASCII characters are always returned, I think __ascii_ would be a better name. I'd expect a method called __bytes__ on

Re: [Python-Dev] Common subset of python 2 and python 3

2014-01-15 Thread Steven D'Aprano
On Wed, Jan 15, 2014 at 09:25:04AM -0500, Eric V. Smith wrote: On 1/15/2014 8:21 AM, Chris Angelico wrote: On Wed, Jan 15, 2014 at 11:22 PM, Martin v. Löwis mar...@v.loewis.de wrote: I don't think that it is possible to write an interpreter that is fully compatible for all it accepts.

Re: [Python-Dev] PEP 461 - Adding % and {} formatting to bytes

2014-01-15 Thread Steven D'Aprano
On Wed, Jan 15, 2014 at 10:34:48PM +, Mark Lawrence wrote: On 15/01/2014 22:22, Brett Cannon wrote: On Wed, Jan 15, 2014 at 5:00 PM, Steven D'Aprano st...@pearwood.info mailto:st...@pearwood.info wrote: On Thu, Jan 16, 2014 at 10:55:31AM +1300, Greg Ewing wrote: Neil

Re: [Python-Dev] PEP 461 - Adding % and {} formatting to bytes

2014-01-15 Thread Steven D'Aprano
On Wed, Jan 15, 2014 at 05:46:07PM -0800, Glenn Linderman wrote: On 1/15/2014 4:03 PM, Steven D'Aprano wrote: What precisely does it do? If it's so obvious, why is this thread so long? It produces a formatted representation of the object in bytes. For numbers, that would probably

Re: [Python-Dev] PEP 461 updates

2014-01-16 Thread Steven D'Aprano
On Fri, Jan 17, 2014 at 11:19:44AM +0900, Stephen J. Turnbull wrote: Meta enough that I'll take Guido out of the CC. Nick Coghlan writes: There are plenty of data formats (like SMTP and HTTP) that are constrained to be ASCII compatible, ASCII compatible is a technical term in

Re: [Python-Dev] PEP 461 - Adding % and {} formatting to bytes

2014-01-16 Thread Steven D'Aprano
On Thu, Jan 16, 2014 at 08:23:13AM -0800, Ethan Furman wrote: As I understand it, str.format will call the object's __format__. So, for example, if I say: u'the value is: %d' % myNum(17) then it will be myNum.__format__ that gets called, not int.__format__; I seem to have missed

Re: [Python-Dev] AC Derby and accepting None for optional positional arguments

2014-01-17 Thread Steven D'Aprano
On Thu, Jan 16, 2014 at 01:08:47PM -0800, Ryan Smith-Roberts wrote: socket.getservbyname(servicename[, protocolname]) This is not an inspectable signature, since pure Python does not support bracketed arguments. To make it inspectable, we must give protocolname a (valid Python) default

Re: [Python-Dev] PEP 461 Final?

2014-01-17 Thread Steven D'Aprano
On Fri, Jan 17, 2014 at 08:49:21AM -0800, Ethan Furman wrote: Overriding Principles = In order to avoid the problems of auto-conversion and Unicode exceptions that could plague Py2 code, all object checking will be done by duck-typing, not by values contained in a

Re: [Python-Dev] PEP 461 Final?

2014-01-19 Thread Steven D'Aprano
On Fri, Jan 17, 2014 at 05:51:05PM -0800, Ethan Furman wrote: On 01/17/2014 05:27 PM, Steven D'Aprano wrote: Numeric Format Codes To properly handle int and float subclasses, int(), index(), and float() will be called on the objects intended for (d, i, u), (b, o, x, X

Re: [Python-Dev] str.rreplace

2014-01-24 Thread Steven D'Aprano
On Sat, Jan 25, 2014 at 10:41:05AM +1000, Nick Coghlan wrote: In this specific case, our general communication about the different purposes of the core lists *isn't* particularly good, Nick, I beg to differ: I think that our communication in this regard actually is quite reasonable. Before

Re: [Python-Dev] Quick poll: should help() show bound arguments?

2014-01-24 Thread Steven D'Aprano
On Fri, Jan 24, 2014 at 08:07:43PM -0800, Larry Hastings wrote: (Quick, because apparently nobody reads the long ones!) In Python 3.3: class C: ...def foo(self, a): pass ... c = C() help(c.foo) shows you the signature foo(self, a). That matches the

Re: [Python-Dev] Negative times behaviour in itertools.repeat for Python maintenance releases (2.7, 3.3 and maybe 3.4)

2014-01-26 Thread Steven D'Aprano
On Sun, Jan 26, 2014 at 11:40:33PM -0500, Alexander Belopolsky wrote: I would say no fix is needed for this doc because the signature suggests (correctly) that passing times by keyword is not supported. How do you determine that? Passing times by keyword works in Python 3.3: py from itertools

Re: [Python-Dev] Negative times behaviour in itertools.repeat for Python maintenance releases (2.7, 3.3 and maybe 3.4)

2014-01-27 Thread Steven D'Aprano
On Mon, Jan 27, 2014 at 04:29:04AM -0800, Larry Hastings wrote: The code currently has semantics that cannot be accurately represented in a Python signature. We could do one of three things: 1) Do nothing, and don't allow inspect.Signature to produce a signature for the function. This

Re: [Python-Dev] Negative times behaviour in itertools.repeat for Python maintenance releases (2.7, 3.3 and maybe 3.4)

2014-01-28 Thread Steven D'Aprano
On Mon, Jan 27, 2014 at 10:06:57PM -0800, Larry Hastings wrote: If I were writing it, it might well come out like this: [snip example] +1 on this wording, with one minor caveat: .. note: if times is specified using a keyword argument, and provided with a negative value, repeat yields

Re: [Python-Dev] Negative times behaviour in itertools.repeat for Python maintenance releases (2.7, 3.3 and maybe 3.4)

2014-01-31 Thread Steven D'Aprano
On Fri, Jan 31, 2014 at 07:23:52PM -0800, Larry Hastings wrote: Python is the language that cares about backwards-compatibility--bugs and all. If your code runs on version X.Y, it should run without modification on version X.(Y+Z) where Z is a positive integer. Therefore it would be

Re: [Python-Dev] Negative times behaviour in itertools.repeat for Python maintenance releases (2.7, 3.3 and maybe 3.4)

2014-02-01 Thread Steven D'Aprano
On Sat, Feb 01, 2014 at 10:20:24PM +1000, Nick Coghlan wrote: On 1 February 2014 16:04, Ethan Furman et...@stoneleaf.us wrote: So we only fix bugs that don't work at all? By which I mean, if the interpreter doesn't crash, we don't fix it? No, we make a judgment call based on the severity

[Python-Dev] Guidance regarding what counts as breaking backwards compatibility

2014-02-01 Thread Steven D'Aprano
Hi all, Over on the Python-ideas list, there's a thread about the new statistics module, and as the author of that module, I'm looking for a bit of guidance regarding backwards compatibility. Specifically two issues: (1) With numeric code, what happens if the module become more[1] accurate

Re: [Python-Dev] PEP 463: Exception-catching expressions

2014-02-21 Thread Steven D'Aprano
On Sat, Feb 22, 2014 at 01:15:13PM +1300, Greg Ewing wrote: Eli Bendersky wrote: For instance, it is sometime non-trivial to know which exceptions some function may throw. When you write a try...raise statement, you think hard about covering all the bases. In an expression you're unlikely

Re: [Python-Dev] PEP 463: Exception-catching expressions

2014-02-21 Thread Steven D'Aprano
On Fri, Feb 21, 2014 at 04:42:36PM -0800, Ethan Furman wrote: This is not just about better handling of [missing] default values, but of better exception handling. This PEP adds the ability to use a scalpel instead of a sledge hammer. Beautifully said! -- Steven

Re: [Python-Dev] PEP 463: Exception-catching expressions

2014-02-21 Thread Steven D'Aprano
On Fri, Feb 21, 2014 at 02:04:45PM -0500, Yury Selivanov wrote: Inconvenience of dict[] raising KeyError was solved by introducing the dict.get() method. And I think that dct.get('a', 'b') is 1000 times better than dct['a'] except KeyError: 'b' I don't think it is better. I think that

Re: [Python-Dev] PEP 463: Exception-catching expressions

2014-03-05 Thread Steven D'Aprano
On Wed, Mar 05, 2014 at 12:57:03PM -0800, Thomas Wouters wrote: On Thu, Feb 27, 2014 at 1:29 PM, Chris Angelico ros...@gmail.com wrote: +Had this facility existed early in Python's history, there would have been +no need to create dict.get() and related methods; FWIW, after

Re: [Python-Dev] Python 4: don't remove anything, don't break backward compatibility

2014-03-10 Thread Steven D'Aprano
On Mon, Mar 10, 2014 at 02:55:26PM +0100, Victor Stinner wrote: [...] So can we please try to stop scheduling another major Python version breaking almost all modules and all applications just to be pendantic? No, we should not remove any old feature in Python 4. Python 4 should be just a

Re: [Python-Dev] PEP 463: Exception-catching expressions

2014-03-13 Thread Steven D'Aprano
On Thu, Mar 13, 2014 at 07:54:18AM +1100, Chris Angelico wrote: On Thu, Mar 13, 2014 at 7:26 AM, Martin v. Löwis mar...@v.loewis.de wrote: I think you (or someone) first needs to find a BDFL delegate. Traditionally, with syntax changes, there is a good chance that Guido doesn't want to

Re: [Python-Dev] [Python-ideas] itertools.chunks(iterable, size, fill=None)

2012-07-05 Thread Steven D'Aprano
anatoly techtonik wrote: On Wed, Jul 4, 2012 at 9:31 PM, Terry Reedy tjre...@udel.edu wrote: A sliding window for a generic iterable requires a deque or ring buffer approach that is quite different from the zip-longest -- grouper approach. That's why I'd like to drastically reduce the scope

Re: [Python-Dev] [Python-ideas] itertools.chunks(iterable, size, fill=None)

2012-07-05 Thread Steven D'Aprano
anatoly techtonik wrote: Which is the 33th most voted Python question on SO - http://stackoverflow.com/questions/312443/how-do-you-split-a-list-into-evenly-sized-chunks-in-python/312464 I am curious how you get that number. I do note that there are about 15 other Python SO questions that seem

Re: [Python-Dev] PEP 0424: A method for exposing a length hint

2012-07-15 Thread Steven D'Aprano
Nick Coghlan wrote: On Sun, Jul 15, 2012 at 9:18 AM, Benjamin Peterson benja...@python.org wrote: Open questions == There are two open questions for this PEP: * Should ``list`` expose a kwarg in it's constructor for supplying a length hint. * Should a function be added either to

Re: [Python-Dev] PEP 0424: A method for exposing a length hint

2012-07-15 Thread Steven D'Aprano
Antoine Pitrou wrote: The point is that 0 is a legitimate value for a length hint. Simple implementations of __length_hint__ will start returning 0 as a legitimate value and you will wrongly interpret that as don't know, which kinds of defeat the purpose of __length-hint__ ;) That said, I

Re: [Python-Dev] PEP 0424: A method for exposing a length hint

2012-07-15 Thread Steven D'Aprano
Mark Shannon wrote: So how does an iterator express infinite length? The suggestion was it should return -1. What should happen if I am silly enough to do this: list(itertools.count()) This will fail; it should fail quickly. That depends on your OS. I've just tested it now on Linux

Re: [Python-Dev] PEP 0424: A method for exposing a length hint

2012-07-15 Thread Steven D'Aprano
Antoine Pitrou wrote: First, you can't implement __length_hint__ for a generator, which is the preferred (the most practical) way of writing iterators in pure Python. Limitations of generators are no reason for not improving iterators which are not generators. __length_hint__ already exists;

<    1   2   3   4   5   6   7   8   9   10   >