[Python-ideas] Re: SQL string prefix idea

2020-03-15 Thread Stephen J. Turnbull
Kyle Stanley writes: > The behavior is the same on Python 3.8.2: > > Python 3.8.2 (default, Feb 26 2020, 22:21:03) > [GCC 9.2.1 20200130] on linux > Type "help", "copyright", "credits" or "license" for more information. > >>> r'x\'y' > "x\\'y" This looks like a defect to me. The "'"

[Python-ideas] Re: dunder methods for encoding & prettiness aware formal & informal representations

2020-03-15 Thread Stephen J. Turnbull
Christopher Barker writes: > So [inf and -inf] are not "readable input, part of Python syntax", > but they are part of the float API. Thank you for the correction. Aside: help(float) doesn't mention these aspects of the API. I guess that since 1.0 / 0.0 doesn't return float("inf") and 0.0 /

[Python-ideas] Re: dunder methods for encoding & prettiness aware formal & informal representations

2020-03-15 Thread Wes Turner
On Mon, Mar 16, 2020, 1:04 AM Greg Ewing wrote: > On 16/03/20 2:27 pm, Christopher Barker wrote: > > I imagine a LOT of code out there (doctests, who know > > what else) does in fact expect the str() of builtins not to change -- so > > this is probably dead in the water. > > Also, strs and reprs

[Python-ideas] Re: dunder methods for encoding & prettiness aware formal & informal representations

2020-03-15 Thread Greg Ewing
On 16/03/20 2:27 pm, Christopher Barker wrote: I imagine a LOT of code out there (doctests, who know what else) does in fact expect the str() of builtins not to change -- so this is probably dead in the water. Also, strs and reprs of arbitrary objects often end up in places such as log files

[Python-ideas] Re: Adding a built-in data structure with binary search tree semantics

2020-03-15 Thread Andrew Barnert via Python-ideas
> On Mar 15, 2020, at 06:25, 1njecti...@gmail.com wrote: > > In other languages, there are built-in data structures with binary search > tree semantics, as an example, std::map in C++. There have been multiple past discussions on this, which you should search for and read, but I can summarize

[Python-ideas] Re: Magnitude and ProtoMagnitude ABCs — primarily for argument validation

2020-03-15 Thread Steve Jorgensen
Steve Jorgensen wrote: > Steve Jorgensen wrote: > > Steve Jorgensen wrote: > > > > The problem I came up with trying to spike out > > my > > proposal last night is that there > > doesn't seem to be anyway to implement it without creating infinite > > recursion in the > > issublcass call. If I

[Python-ideas] Re: SQL string prefix idea

2020-03-15 Thread Wes Turner
There are many variants of SQL. DB-API only solves for so much. >From "[Python-ideas] Draft PEP on string interpolation" (=> f-strings) https://groups.google.com/d/msg/python-ideas/6tfm3e2UtDU/8ugqbZtYAwAJ : ```quote IIUC, to do this with SQL, > sql(i'select {date:as_date} from {tablename}'

[Python-ideas] Re: dunder methods for encoding & prettiness aware formal & informal representations

2020-03-15 Thread Wes Turner
- CPython has __str__ and __repr__, IPython has obj._repr_fmt_(), MarkupSafe has obj.__html__(), https://github.com/tommikaikkonen/prettyprinter has @register_pretty Neither __str__ nor __repr__ have any round-trip guarantee/expectation (they're not suitable for serialization/deserialization //

[Python-ideas] Re: dunder methods for encoding & prettiness aware formal & informal representations

2020-03-15 Thread Steven D'Aprano
On Sun, Mar 15, 2020 at 06:27:43PM -0700, Christopher Barker wrote: > Anyway, Python now has two different ways to "turn this into a string":, > __str__ and __repr__. I think the OP is suggesting a third, for "pretty > version". But then maybe folks would want a fourth or fifth, or . > >

[Python-ideas] Re: dunder methods for encoding & prettiness aware formal & informal representations

2020-03-15 Thread Kyle Stanley
Christopher Barker wrote: > Is there any guarantee (or even string expectation) that the __str__ for an object won't change? > [snip] > *reality check*: I imagine a LOT of code out there (doctests, who know what else) does in fact expect the str() of builtins not to change -- so this is probably

[Python-ideas] Re: dunder methods for encoding & prettiness aware formal & informal representations

2020-03-15 Thread Christopher Barker
On Sun, Mar 15, 2020 at 6:12 PM Stephen J. Turnbull < turnbull.stephen...@u.tsukuba.ac.jp> wrote: > Also, I'd like to note that "inf" and "-inf" (and "nan" for that > matter) are not "informal". They are readable input, part of Python > syntax: > > % python3.8 > Python 3.8.2 (default, Feb 27

[Python-ideas] Re: SQL string prefix idea

2020-03-15 Thread Kyle Stanley
Rob Cliffe wrote: > Your docs link states "... they allow you to pass on the string quote > character by escaping it with a backslash." > > I don't have access to a Python 3 version right now, but that is not > true in Python 2: > [snip] The behavior is the same on Python 3.8.2: Python 3.8.2

[Python-ideas] Re: dunder methods for encoding & prettiness aware formal & informal representations

2020-03-15 Thread Stephen J. Turnbull
Jonathan Fine writes: > However, you wrote "decide implicitly". Perhaps I'm missing something in > the "implicitly". That's shorthand for the long form I used later: "depending on variable environment state" (such as encodings, user id, or sunspot activity). Should have done it in the

[Python-ideas] Re: dunder methods for encoding & prettiness aware formal & informal representations

2020-03-15 Thread Eric V. Smith
On 3/15/2020 12:50 PM, Steve Jorgensen wrote: Guido van Rossum wrote: I think the idea you're looking for is an alternative for the pprint module that allows classes to have formatting hooks that get passed in some additional information (or perhaps a PrettyPrinter object) that can affect the

[Python-ideas] Re: Adding a built-in data structure with binary search tree semantics

2020-03-15 Thread Soni L.
On 2020-03-15 5:19 p.m., Chris Angelico wrote: On Mon, Mar 16, 2020 at 7:14 AM Christopher Barker wrote: > But back the python_ideas topic: > > It might be good to have a set of real, tree-based data structures -- they are the best way to go for some use cases, and are non-trivial to

[Python-ideas] Re: Adding a built-in data structure with binary search tree semantics

2020-03-15 Thread Marco Sulla
On Sun, 15 Mar 2020 at 20:27, Alex Hall wrote: > How about http://www.grantjenks.com/docs/sortedcontainers/sorteddict.html > ? > There's also Sorted Containers, that seems to be a mature project: http://www.grantjenks.com/docs/sortedcontainers/index.html

[Python-ideas] Re: SQL string prefix idea

2020-03-15 Thread Chris Angelico
On Mon, Mar 16, 2020 at 9:08 AM Rob Cliffe via Python-ideas wrote: > > > On 22/02/2020 06:26, Steven D'Aprano wrote: > > > > Actually, in Python, regexes are the primary reason raw strings were > > added! > > > > Raw strings aren't quite fully raw, which is why you can't use raw > > strings for

[Python-ideas] Re: SQL string prefix idea

2020-03-15 Thread Rob Cliffe via Python-ideas
On 22/02/2020 06:26, Steven D'Aprano wrote: Actually, in Python, regexes are the primary reason raw strings were added! Raw strings aren't quite fully raw, which is why you can't use raw strings for Windows paths: path = r'somewhere\some\folder\' doesn't work. The reason is that "raw"

[Python-ideas] Re: Adding a built-in data structure with binary search tree semantics

2020-03-15 Thread Christopher Barker
On Sun, Mar 15, 2020 at 1:20 PM Chris Angelico wrote: > Recommendation: If anything is added to the standard library, it > should be named according to its use-cases, not its implementation. > Agreed. Which is why I named my toy SortedMap :-) However, what if we made another, e.g. Mapping,

[Python-ideas] Re: Adding a built-in data structure with binary search tree semantics

2020-03-15 Thread Chris Angelico
On Mon, Mar 16, 2020 at 7:14 AM Christopher Barker wrote: > But back the python_ideas topic: > > It might be good to have a set of real, tree-based data structures -- they > are the best way to go for some use cases, and are non-trivial to implement > well. > > (and yes, starting out at a third

[Python-ideas] Re: Adding a built-in data structure with binary search tree semantics

2020-03-15 Thread Christopher Barker
On Sun, Mar 15, 2020 at 12:28 PM Alex Hall wrote: > How about http://www.grantjenks.com/docs/sortedcontainers/sorteddict.html > ? > For my part, I didn't look for that, as I was having fun playing around with the idea. But yes, that looks like it would fit the bill. And at a glance, they were

[Python-ideas] Re: Adding a built-in data structure with binary search tree semantics

2020-03-15 Thread Alex Hall
How about http://www.grantjenks.com/docs/sortedcontainers/sorteddict.html ? ___ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org

[Python-ideas] Re: Adding a built-in data structure with binary search tree semantics

2020-03-15 Thread Christopher Barker
> > > In other languages, there are built-in data structures with binary > > search tree semantics, as an example, std::map in C++. > not being a C++ guy, I had no idea that std::map was a tree -- I always figured it was a hashtable, but you learn something new every day. As far as I know, there

[Python-ideas] Re: dunder methods for encoding & prettiness aware formal & informal representations

2020-03-15 Thread Steve Jorgensen
Alex Hall wrote: > Might be helpful to look at https://github.com/tommikaikkonen/prettyprinter > and https://github.com/wolever/pprintpp Right! Thx. :) ___ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to

[Python-ideas] Re: dunder methods for encoding & prettiness aware formal & informal representations

2020-03-15 Thread Steve Jorgensen
Jonathan Fine wrote: > Hi Steve (for clarity Jorgensen) > Thank you for your good idea, and your enthusiasm. And I thank Guido, for > suggesting a good contribution this list can make. > Here's some comments on the state of the art. In addition to > https://docs.python.org/3/library/pprint.html >

[Python-ideas] Re: dunder methods for encoding & prettiness aware formal & informal representations

2020-03-15 Thread Alex Hall
Might be helpful to look at https://github.com/tommikaikkonen/prettyprinter and https://github.com/wolever/pprintpp ___ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org

[Python-ideas] Re: dunder methods for encoding & prettiness aware formal & informal representations

2020-03-15 Thread Jonathan Fine
Hi Steve (for clarity Jorgensen) Thank you for your good idea, and your enthusiasm. And I thank Guido, for suggesting a good contribution this list can make. Here's some comments on the state of the art. In addition to https://docs.python.org/3/library/pprint.html there's also

[Python-ideas] Re: dunder methods for encoding & prettiness aware formal & informal representations

2020-03-15 Thread Jonathan Fine
Hi Steve (for clarity Turnbull) You wrote: Allowing objects to decide implicitly how to represent themselves is usually a bad idea, and we shouldn't encourage it. I'm puzzled. I thought that when I define a class X, I'm generally encouraged to define a __repr__ method, that is used to decide how

[Python-ideas] Re: dunder methods for encoding & prettiness aware formal & informal representations

2020-03-15 Thread Steve Jorgensen
Guido van Rossum wrote: > I think the idea you're looking for is an alternative for the pprint module > that allows classes to have formatting hooks that get passed in some > additional information (or perhaps a PrettyPrinter object) that can affect > the formatting. > This would seem to be an

[Python-ideas] dunder methods for encoding & prettiness aware formal & informal representations

2020-03-15 Thread Stephen J. Turnbull
Steve Jorgensen writes: > Encoding awareness: > > The informal (`str`) representations of `inf` and `-inf` are "inf" > and "-inf", and that seems appropriate as a known-safe value, but > if we're writing the representation to a stream, and the stream has > a Unicode encoding, then those

[Python-ideas] Re: dunder methods for encoding & prettiness aware formal & informal representations

2020-03-15 Thread Guido van Rossum
I think the idea you're looking for is an alternative for the pprint module that allows classes to have formatting hooks that get passed in some additional information (or perhaps a PrettyPrinter object) that can affect the formatting. This would seem to be an ideal thing to try to design and put

[Python-ideas] Re: Adding a built-in data structure with binary search tree semantics

2020-03-15 Thread Dan Sommers
On Sat, 14 Mar 2020 20:35:08 - 1njecti...@gmail.com wrote: > In other languages, there are built-in data structures with binary > search tree semantics, as an example, std::map in C++. > By binary search tree semantics we mean the following: > * We can insert elements into the structure in

[Python-ideas] Adding a built-in data structure with binary search tree semantics

2020-03-15 Thread 1njection1
In other languages, there are built-in data structures with binary search tree semantics, as an example, std::map in C++. By binary search tree semantics we mean the following: * We can insert elements into the structure in time faster than O(n), i.e. O(logn) for std::map * We can iterate over

[Python-ideas] dunder methods for encoding & prettiness aware formal & informal representations

2020-03-15 Thread Steve Jorgensen
This is really an idea for an idea. I'm not sure what the ideal dunder method names or APIs should be. Encoding awareness: The informal (`str`) representations of `inf` and `-inf` are "inf" and "-inf", and that seems appropriate as a known-safe value, but if we're writing the representation