[Python-ideas] Re: Custom string prefixes

2019-08-29 Thread Paul Moore
On Thu, 29 Aug 2019 at 22:12, Andrew Barnert via Python-ideas wrote: > As I’ve said before, I believe that anything that doesn’t have a builtin type > does not deserve builtin syntax. And I don’t understand why that isn’t a > near-ubiquitous viewpoint. But it’s not just you; at least three peopl

[Python-ideas] Re: Inspired by Scala, a new syntax for Union type

2019-08-29 Thread Rob Cliffe via Python-ideas
On 29/08/2019 15:32:38, Philippe Prados wrote: I try with +fooin place of ~foo. Kotlin propose the null-safety  with foo?, but this syntax has a impact of the BNF and all others tools. Le jeu. 29 août 2019 à 15:58, Ricky Teachey

[Python-ideas] Re: Inspired by Scala, a new syntax for Union type

2019-08-29 Thread Guido van Rossum
On Thu, Aug 29, 2019 at 7:14 PM Andrew Barnert wrote: > What about other constructs that take a tuple of types? Should try/except > take sets? (Are there any others?) > > Would anyone be surprised that isinstance/issubclass take a tuple or set > of types but all those string methods take only a t

[Python-ideas] Re: Custom string prefixes

2019-08-29 Thread Andrew Barnert via Python-ideas
On Aug 29, 2019, at 16:58, Greg Ewing wrote: > > Steven D'Aprano wrote: >> I don't think that stpa...@gmail.com means that the user literally assigns >> to locals() themselves. I read his proposal as having the compiler >> automatical mangle the names in some way, similar to name mangling insid

[Python-ideas] Re: Inspired by Scala, a new syntax for Union type

2019-08-29 Thread Andrew Barnert via Python-ideas
On Aug 29, 2019, at 18:10, Guido van Rossum wrote: > >> On Thu, Aug 29, 2019 at 5:56 PM Andrew Barnert via Python-ideas >> wrote: >> I think {int, str}, which someone proposed in one of the earlier >> discussions, is nice. What else would a set of types mean (unless you’re >> doing mathematic

[Python-ideas] Re: Inspired by Scala, a new syntax for Union type

2019-08-29 Thread Andrew Barnert via Python-ideas
On Aug 29, 2019, at 16:32, Guido van Rossum wrote: > > Surely the meaning of `?` in a programming language also has to be learned. > And not every language uses it to mean "optional" (IIRC there's a language > where it means "boolean" -- maybe Scheme?) Sure, ? does mean lots of different thing

[Python-ideas] Re: Inspired by Scala, a new syntax for Union type

2019-08-29 Thread Guido van Rossum
On Thu, Aug 29, 2019 at 5:56 PM Andrew Barnert via Python-ideas < python-ideas@python.org> wrote: > I think {int, str}, which someone proposed in one of the earlier > discussions, is nice. What else would a set of types mean (unless you’re > doing mathematical type theory rather than programming l

[Python-ideas] Re: Inspired by Scala, a new syntax for Union type

2019-08-29 Thread Andrew Barnert via Python-ideas
On Aug 29, 2019, at 16:03, Dominik Vilsmeier wrote: > > I never really understood the importance of `Optional`. Often it can be left > out altogether and in other cases I find `Union[T, None]` more expressive > (explicit) than `Optional[T]` (+ the latter saves only 3 chars). > Especially for p

[Python-ideas] Re: Inspired by Scala, a new syntax for Union type

2019-08-29 Thread Guido van Rossum
Possibly relevant for tilde: https://www.thecut.com/article/why-the-internet-tilde-is-our-most-perfect-tool-for-snark.html On Thu, Aug 29, 2019 at 5:09 PM Dominik Vilsmeier wrote: > Guido van Rossum wrote: > > On Thu, Aug 29, 2019 at 4:04 PM Dominik Vilsmeier > dominik.vilsme...@gmx.de > > wrote

[Python-ideas] Re: Inspired by Scala, a new syntax for Union type

2019-08-29 Thread Dominik Vilsmeier
Guido van Rossum wrote: > On Thu, Aug 29, 2019 at 4:04 PM Dominik Vilsmeier dominik.vilsme...@gmx.de > wrote: > > I never really understood the importance of > > Optional. Often it can be > > left out altogether and in other cases I find Union[T, None] more > > expressive (explicit) than Optional[T

[Python-ideas] Re: Inspired by Scala, a new syntax for Union type

2019-08-29 Thread Guido van Rossum
On Thu, Aug 29, 2019 at 5:00 PM Andrew Barnert wrote: > On Aug 29, 2019, at 15:28, Guido van Rossum wrote: > > > > A wart will be that we can make `int | None` work but we shouldn't make > `None | int` work (I don't want to add any new operator overloads to > `None`, it should always be an error

[Python-ideas] Re: Inspired by Scala, a new syntax for Union type

2019-08-29 Thread Andrew Barnert via Python-ideas
On Aug 29, 2019, at 15:28, Guido van Rossum wrote: > > A wart will be that we can make `int | None` work but we shouldn't make `None > | int` work (I don't want to add any new operator overloads to `None`, it > should always be an error). Is there a reason that type.__ror__ wouldn’t handle tha

[Python-ideas] Re: Custom string prefixes

2019-08-29 Thread Greg Ewing
Steven D'Aprano wrote: I don't think that stpa...@gmail.com means that the user literally assigns to locals() themselves. I read his proposal as having the compiler automatical mangle the names in some way, similar to name mangling inside classes. Yes, but at some point you have to define a f

[Python-ideas] Re: Custom string prefixes

2019-08-29 Thread Greg Ewing
Rhodri James wrote: Suppose that we did have some funky mechanism to get the compiler to create objects at compile time It doesn't necessarily have to be at compile time. It can be at run time, as long as it only happens once. So we use "start_date" somewhere, and mutate it because the start d

[Python-ideas] Re: Inspired by Scala, a new syntax for Union type

2019-08-29 Thread Guido van Rossum
On Thu, Aug 29, 2019 at 4:04 PM Dominik Vilsmeier wrote: > I never really understood the importance of `Optional`. Often it can be > left out altogether and in other cases I find `Union[T, None]` more > expressive (explicit) than `Optional[T]` (+ the latter saves only 3 chars). > I respectfully

[Python-ideas] Re: Inspired by Scala, a new syntax for Union type

2019-08-29 Thread Guido van Rossum
On Thu, Aug 29, 2019 at 3:55 PM Chris Angelico wrote: > On Fri, Aug 30, 2019 at 8:43 AM Guido van Rossum wrote: > > > > On Thu, Aug 29, 2019 at 3:33 PM Chris Angelico wrote: > >> > >> On Fri, Aug 30, 2019 at 8:28 AM Guido van Rossum > wrote: > >> > Open question: at runtime, what should `int |

[Python-ideas] Re: Inspired by Scala, a new syntax for Union type

2019-08-29 Thread Dominik Vilsmeier
I never really understood the importance of `Optional`. Often it can be left out altogether and in other cases I find `Union[T, None]` more expressive (explicit) than `Optional[T]` (+ the latter saves only 3 chars). Especially for people not familiar with typing, the meaning of `Optional` is no

[Python-ideas] Re: Inspired by Scala, a new syntax for Union type

2019-08-29 Thread Chris Angelico
On Fri, Aug 30, 2019 at 8:43 AM Guido van Rossum wrote: > > On Thu, Aug 29, 2019 at 3:33 PM Chris Angelico wrote: >> >> On Fri, Aug 30, 2019 at 8:28 AM Guido van Rossum wrote: >> > Open question: at runtime, what should `int | str` return? I don't want >> > this to have to import the typing mod

[Python-ideas] Re: Inspired by Scala, a new syntax for Union type

2019-08-29 Thread Guido van Rossum
On Thu, Aug 29, 2019 at 3:33 PM Chris Angelico wrote: > On Fri, Aug 30, 2019 at 8:28 AM Guido van Rossum wrote: > > Open question: at runtime, what should `int | str` return? I don't want > this to have to import the typing module. Maybe we could make a very simple > `Union` builtin. This can th

[Python-ideas] Re: Custom string prefixes

2019-08-29 Thread Eric V. Smith
One way to handle this particular case would be to do it as a variant of f-string that doesn't join its arguments, but passes the list to some other function. Just replace the final step BUILD_STRING step with BUILD_LIST, then call the function. There'd need to be some way to recognize which se

[Python-ideas] Re: Inspired by Scala, a new syntax for Union type

2019-08-29 Thread Chris Angelico
On Fri, Aug 30, 2019 at 8:28 AM Guido van Rossum wrote: > Open question: at runtime, what should `int | str` return? I don't want this > to have to import the typing module. Maybe we could make a very simple > `Union` builtin. This can then also be used by `~int` (which is equivalent to > `int

[Python-ideas] Re: Add a `dig` method to dictionaries supporting the retrieval of nested keys

2019-08-29 Thread Dominik Vilsmeier
This sounds to me like functionality of a specific type (more specific than `dict`). `dict` can have any key-value pairs, it is not necessarily a nested structure of dicts. Thus having a method for such a specific use case with the general dict type doesn't feel right. I think it's better if su

[Python-ideas] Re: Inspired by Scala, a new syntax for Union type

2019-08-29 Thread Guido van Rossum
On Thu, Aug 29, 2019 at 2:59 PM Andrew Barnert via Python-ideas < python-ideas@python.org> wrote: > It doesn’t make Python backward incompatible; it does mean that if typing > or mypy relies on it, it becomes incompatible with earlier versions of > Python (or has to fork different code for 3.8+ th

[Python-ideas] Re: Inspired by Scala, a new syntax for Union type

2019-08-29 Thread Chris Angelico
On Fri, Aug 30, 2019 at 7:59 AM Andrew Barnert wrote: > > On Aug 29, 2019, at 12:54, Chris Angelico wrote: > > >> Either one seems a lot better than breaking backward compatibility by > >> adding new operator methods to the type type. > >> > > > > How does that break backward compat? > > It does

[Python-ideas] Re: Custom string prefixes

2019-08-29 Thread Rob Cliffe via Python-ideas
On 29/08/2019 22:10:21, Andrew Barnert via Python-ideas wrote: As I’ve said before, I believe that anything that doesn’t have a builtin type does not deserve builtin syntax. And I don’t understand why that isn’t a near-ubiquitous viewpoint. +1 (maybe that means I'm missing something). Just cu

[Python-ideas] Re: Inspired by Scala, a new syntax for Union type

2019-08-29 Thread Andrew Barnert via Python-ideas
On Aug 29, 2019, at 12:54, Chris Angelico wrote: >> Either one seems a lot better than breaking backward compatibility by adding >> new operator methods to the type type. >> > > How does that break backward compat? It doesn’t make Python backward incompatible; it does mean that if typing or

[Python-ideas] Re: Add a `dig` method to dictionaries supporting the retrieval of nested keys

2019-08-29 Thread Ricky Teachey
Have you considered using collections.ChainMap for this kind of thing? The root/first dictionary keys could each refer to the nested dictionaries, and you could access all the nested keys like this: my_chainmap.parents.keys() ___ Python-ideas mailing li

[Python-ideas] Re: Add a `dig` method to dictionaries supporting the retrieval of nested keys

2019-08-29 Thread Guido van Rossum
Have you tried writing your own helper function `dig(d, *args)`? It should only take a few lines, and you can easily put that in a library of "utility" functions you carry around with you from project to project. Not everything needs to be built in! On Thu, Aug 29, 2019 at 1:53 PM None via Python-

[Python-ideas] Re: Custom string prefixes

2019-08-29 Thread Andrew Barnert via Python-ideas
On Aug 29, 2019, at 07:52, Steven D'Aprano wrote: > >> On Thu, Aug 29, 2019 at 05:30:39AM -0700, Andrew Barnert wrote: >>> On Aug 29, 2019, at 04:58, Steven D'Aprano wrote: >>> >>> - quote marks are also used for function calls, but only a limited >>> subset of function calls (those which take

[Python-ideas] Re: Inspired by Scala, a new syntax for Union type

2019-08-29 Thread Steven D'Aprano
On Thu, Aug 29, 2019 at 02:25:56PM +0200, Philippe Prados wrote: > # Operator for Union > assert( int | str == Union[int,str]) [Aside: assert is not a function and you don't need the parentheses.] This is not a new proposal. If I recall correctly, it was proposed way back at the very beginning

[Python-ideas] Add a `dig` method to dictionaries supporting the retrieval of nested keys

2019-08-29 Thread None via Python-ideas
I did some searching to see if this has already been proposed before, but didn't find any evidence that it has. If so, let me know and I'll go away :) One of the tasks that I encounter frequently enough is retrieving a nested key from a nested collection of dictionaries (a dictionary of diction

[Python-ideas] Re: Inspired by Scala, a new syntax for Union type

2019-08-29 Thread Chris Angelico
On Fri, Aug 30, 2019 at 5:46 AM Andrew Barnert via Python-ideas wrote: > > On Aug 29, 2019, at 12:09, Dominik Vilsmeier wrote: > > > > What about using `(int, str)` for indicating a `Union`? This doesn't have > > compatibility issues and it's similar to `isinstance(foo, (int, str))`, so > > it

[Python-ideas] Re: Inspired by Scala, a new syntax for Union type

2019-08-29 Thread Andrew Barnert via Python-ideas
On Aug 29, 2019, at 12:09, Dominik Vilsmeier wrote: > > What about using `(int, str)` for indicating a `Union`? This doesn't have > compatibility issues and it's similar to `isinstance(foo, (int, str))`, so it > should be fairly intuitive: > >def bar(foo: (int, str) = 0): >... In

[Python-ideas] Re: Custom string prefixes

2019-08-29 Thread Andrew Barnert via Python-ideas
> On Aug 29, 2019, at 06:40, Rhodri James wrote: > > However, it sounds like what you really want is something I've often really > wanted to -- a way to get the compiler to pre-create "constant" objects for > me. People often say they want this, but does anyone actually ever have a good reaso

[Python-ideas] Re: Custom string prefixes

2019-08-29 Thread Pasha Stetsenko
> There's no such thing, though, any more than there's such a thing as a > "raw string". There are only two types of string in Python - text and > bytes. You can't behave differently based on whether you were given a > triple-quoted, raw, or other string literal. A simple implementation could be s

[Python-ideas] Re: Inspired by Scala, a new syntax for Union type

2019-08-29 Thread Dominik Vilsmeier
What about using `(int, str)` for indicating a `Union`? This doesn't have compatibility issues and it's similar to `isinstance(foo, (int, str))`, so it should be fairly intuitive: def bar(foo: (int, str) = 0): ... Also it's similar to `get_args(Union[int, str])`. ___

[Python-ideas] Re: Custom string prefixes

2019-08-29 Thread Richard Damon
On 8/29/19 11:14 AM, Chris Angelico wrote: > On Fri, Aug 30, 2019 at 3:51 AM Pasha Stetsenko wrote: >> My understanding is that for a sql prefix the most valuable part is to be >> able >> to know that it was created from a literal. No other magic, definitely not >> auto-executing. Then it would b

[Python-ideas] Re: Custom string prefixes

2019-08-29 Thread Chris Angelico
On Fri, Aug 30, 2019 at 3:51 AM Pasha Stetsenko wrote: > > My understanding is that for a sql prefix the most valuable part is to be able > to know that it was created from a literal. No other magic, definitely not > auto-executing. Then it would be legal to write > > result = conn.execute(sql

[Python-ideas] Re: Custom string prefixes

2019-08-29 Thread Pasha Stetsenko
> How does one get a value into locals()["re~"]? You're right, I didn't think about that. I agree with Steven's interpretation that the user is not expected to modify locals herself, still the immutable nature of locals presents a considerable challenge. So I'm thinking that perhaps we could chan

[Python-ideas] Re: Custom string prefixes

2019-08-29 Thread Pasha Stetsenko
My understanding is that for a sql prefix the most valuable part is to be able to know that it was created from a literal. No other magic, definitely not auto-executing. Then it would be legal to write result = conn.execute(sql"SELECT * FROM people WHERE id=?", user_

[Python-ideas] Re: Custom string prefixes

2019-08-29 Thread Pasha Stetsenko
My understanding is that for a sql prefix the most valuable part is to be able to know that it was created from a literal. No other magic, definitely not auto-executing. Then it would be legal to write result = conn.execute(sql"SELECT * FROM people WHERE id=?", user_

[Python-ideas] Re: Inspired by Scala, a new syntax for Union type

2019-08-29 Thread Andrew Barnert via Python-ideas
On Aug 29, 2019, at 05:25, Philippe Prados wrote: > > Hello everybody, > Scala 3 propose the a new syntax for Union type. See here. I propose to add a > similar syntax in Python. > # Operator for Union > assert( int | str == Union[int,str]) > assert( int | str | float == Union[int,str,float]) >

[Python-ideas] Re: Custom string prefixes

2019-08-29 Thread Richard Damon
On 8/26/19 4:03 PM, stpa...@gmail.com wrote: > In Python strings are allowed to have a number of special prefixes: > > b'', r'', u'', f'' > + their combinations. > > The proposal is to allow arbitrary (or letter-only) user-defined prefixes as > well. > Essentially, a string prefix would s

[Python-ideas] Re: Inspired by Scala, a new syntax for Union type

2019-08-29 Thread Rhodri James
On 29/08/2019 15:32, Philippe Prados wrote: I try with +foo in place of ~foo. If anything, +foo is less intuitive than ~foo for Optional. -- Rhodri James *-* Kynesim Ltd ___ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an

[Python-ideas] Re: Inspired by Scala, a new syntax for Union type

2019-08-29 Thread Chris Angelico
On Fri, Aug 30, 2019 at 1:17 AM Philippe Prados wrote: > > I propose to use a unary operator to help the readability. With a lot of > parameters: > > def f(source: str | None, destination: str | None, param: int | None):... > > I think it's more readable with > > def f(source: str?, destination:

[Python-ideas] Re: Inspired by Scala, a new syntax for Union type

2019-08-29 Thread Ricky Teachey
> I think it's more readable with > > def f(source: str?, destination: str?, param: int?): ... > > Hmmm. But then with default arguments you end up with: def f(source: str?=def_src, destination: str?=MISSING, param: int?=1): ... ?= looks... not great to me. Though it does look better with spaces:

[Python-ideas] Re: Custom string prefixes

2019-08-29 Thread Paul Moore
On Thu, 29 Aug 2019 at 15:54, Steven D'Aprano wrote: > Let me suggest some design principles that should hold for languages > with more-or-less "conventional" syntax. Languages like APL or Forth > excluded. This will degenerate into nitpicking very fast, so let me just say that I understand the

[Python-ideas] Re: Inspired by Scala, a new syntax for Union type

2019-08-29 Thread Philippe Prados
With PEP 563, there's no runtime behaviors. It's strange to accept : def f() -> int | str: ... but not a = int | str The operator type.__or__() is called only if the user known what they do. it's strictly equivalent to a = Union[int,str] So, I think it's important to add this operator in roo

[Python-ideas] Re: Inspired by Scala, a new syntax for Union type

2019-08-29 Thread Philippe Prados
I propose to use a unary operator to help the readability. With a lot of parameters: def f(source: str | None, destination: str | None, param: int | None):... I think it's more readable with def f(source: str?, destination: str?, param: int?): ... I propose two branches in my implementation: ad

[Python-ideas] Re: Inspired by Scala, a new syntax for Union type

2019-08-29 Thread Ricky Teachey
> > I try with +foo in place of ~foo. > +foo seems a lot better to me than ~foo, but i still lean towards `foo | None` as "good enough". it's 3 fewer characters than `Optional[foo]`, or 30 fewer if you include the full removal of `from typing import Optional`. the additional gain of +foo is only

[Python-ideas] Re: Custom string prefixes

2019-08-29 Thread Steven D'Aprano
On Thu, Aug 29, 2019 at 05:30:39AM -0700, Andrew Barnert wrote: > On Aug 29, 2019, at 04:58, Steven D'Aprano wrote: > > > > - quote marks are also used for function calls, but only a limited > > subset of function calls (those which take a single string literal > > argument). > > This is a dis

[Python-ideas] Re: Inspired by Scala, a new syntax for Union type

2019-08-29 Thread Gustavo Carneiro
On Thu, 29 Aug 2019 at 14:58, Ricky Teachey wrote: > I like this idea. > > >> The ~foo for Optional is... not that obvious. Not sure it's a win. >> >> > I agree. Seems like `foo | None` is just as readable. Assuming that None > would be swapped out for NoneType, of course. > Agreed, `foo | Non

[Python-ideas] Re: Inspired by Scala, a new syntax for Union type

2019-08-29 Thread Philippe Prados
I try with +foo in place of ~foo. Kotlin propose the null-safety with foo?, but this syntax has a impact of the BNF and all others tools. Le jeu. 29 août 2019 à 15:58, Ricky Teachey a écrit : > I like this idea. > > >> The ~foo for Optiona

[Python-ideas] Re: Custom string prefixes

2019-08-29 Thread Rhodri James
On 29/08/2019 14:40, Rhodri James wrote: Pace Stephen's point My apologies, it was Steven's point. -- Rhodri James *-* Kynesim Ltd ___ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org

[Python-ideas] Re: Inspired by Scala, a new syntax for Union type

2019-08-29 Thread Ricky Teachey
I like this idea. > The ~foo for Optional is... not that obvious. Not sure it's a win. > > I agree. Seems like `foo | None` is just as readable. Assuming that None would be swapped out for NoneType, of course. ___ Python-ideas mailing list -- python-i

[Python-ideas] Re: Custom string prefixes

2019-08-29 Thread Steven D'Aprano
On Thu, Aug 29, 2019 at 08:17:39PM +1200, Greg Ewing wrote: > stpa...@gmail.com wrote: > > >re'a|b|c' --becomes--> (locals()["re~"])("a|b|c") > >2.3f --becomes--> (locals()["~f"])("2.3") > > How does one get a value into locals()["re~"]? I don't think that stpa...@gmail.com mean

[Python-ideas] Re: Custom string prefixes

2019-08-29 Thread Steven D'Aprano
On Thu, Aug 29, 2019 at 09:58:35PM +1000, Steven D'Aprano wrote: > Since Python is limited to ASCII syntax, we only have a small number of > symbols suitable for delimiters. With such a small number available, Oops, I had an interrupted thought there. With such a small number available, there

[Python-ideas] Re: Custom string prefixes

2019-08-29 Thread Rhodri James
On 29/08/2019 00:24, Andrew Barnert wrote: On Aug 27, 2019, at 10:21, Rhodri James wrote: You make the point yourself: this is something we already understand from dealing with complex numbers in other circumstances. That is not true of generic single-character string prefixes. It certain

[Python-ideas] Re: Custom string prefixes

2019-08-29 Thread Paul Moore
On Thu, 29 Aug 2019 at 14:21, Andrew Barnert wrote: > You can’t avoid tradeoffs by trying to come up with a rule that makes > language decisions automatically. (If you could, why would this list even > exist?) The closest thing you can get to that is the vague and > self-contradictory and facet

[Python-ideas] Re: Custom string prefixes

2019-08-29 Thread Rhodri James
On 28/08/2019 23:01, stpa...@gmail.com wrote: you have something that looks like a kind of string czt'...' but is really a function call that might return absolutely anything at all; This is kinda the whole point. I understand, of course, how the idea of a string-that-is-not-a-string may sound

[Python-ideas] Re: Inspired by Scala, a new syntax for Union type

2019-08-29 Thread Gustavo Carneiro
I think the "foo | bar" syntax for Union is pretty clear, I like it! The ~foo for Optional is... not that obvious. Not sure it's a win. On Thu, 29 Aug 2019 at 13:49, Philippe Prados wrote: > Hello everybody, > > Scala 3 propose the a new syntax for Union type. See here >

[Python-ideas] Re: Inspired by Scala, a new syntax for Union type

2019-08-29 Thread Philippe Prados
Cool ! My patch of MyPy is allready compatible with this new syntax. Regards Le jeu. 29 août 2019 à 15:11, Inada Naoki a écrit : > > On Thu, Aug 29, 2019 at 10:07 PM Philippe Prados < > philippe.pra...@gmail.com> wrote: > >> ... and, runtime type checking (like >> https://github.com/agronholm

[Python-ideas] Re: Custom string prefixes

2019-08-29 Thread Andrew Barnert via Python-ideas
On Aug 29, 2019, at 00:58, Paul Moore wrote: > > If you > assume everything should be handled by general mechanisms, you end up > at the Lisp/Haskell end of the spectrum. If you decide that the > language defines the limits, you are at the C end. And if you don’t make either assumption, but inst

[Python-ideas] Re: Inspired by Scala, a new syntax for Union type

2019-08-29 Thread Inada Naoki
On Thu, Aug 29, 2019 at 10:07 PM Philippe Prados wrote: > ... and, runtime type checking (like > https://github.com/agronholm/typeguard) must have a synthetised Union[] > in __annotations__. > > > Runtime type checking tools can parse "str | int" too. No need to implement runtime behavior for `st

[Python-ideas] Re: Inspired by Scala, a new syntax for Union type

2019-08-29 Thread Inada Naoki
On Thu, Aug 29, 2019 at 10:03 PM Philippe Prados wrote: > No, it's not possible, because > > >>> int | str > Traceback (most recent call last): > File "", line 1, in > TypeError: unsupported operand type(s) for |: 'type' and 'type' > > Regards > > It is possible because: Python 3.7.4 (default

[Python-ideas] Re: Inspired by Scala, a new syntax for Union type

2019-08-29 Thread Philippe Prados
... and, runtime type checking (like https://github.com/agronholm/typeguard) must have a synthetised Union[] in __annotations__. Le jeu. 29 août 2019 à 15:02, Philippe Prados a écrit : > No, it's not possible, because > > >>> int | str > Traceback (most recent call last): > File "", line 1,

[Python-ideas] Re: Inspired by Scala, a new syntax for Union type

2019-08-29 Thread Philippe Prados
No, it's not possible, because >>> int | str Traceback (most recent call last): File "", line 1, in TypeError: unsupported operand type(s) for |: 'type' and 'type' Regards Philippe Prados Le jeu. 29 août 2019 à 14:55, Inada Naoki a écrit : > I don't want to add runtime behaviors for stati

[Python-ideas] Re: Inspired by Scala, a new syntax for Union type

2019-08-29 Thread Inada Naoki
I don't want to add runtime behaviors for static type hinting. There is PEP 563 instead. Tools like mypy can implement them without touching runtime behavior. On Thu, Aug 29, 2019 at 9:48 PM Philippe Prados wrote: > Hello everybody, > > Scala 3 propose the a new syntax for Union type. See here

[Python-ideas] Inspired by Scala, a new syntax for Union type

2019-08-29 Thread Philippe Prados
Hello everybody, Scala 3 propose the a new syntax for Union type. See here . I propose to add a similar syntax in Python. # Operator for Union assert( int | str == Union[int,str]) assert( int | str | float == Union[int,str,float]) #

[Python-ideas] Re: Custom string prefixes

2019-08-29 Thread Andrew Barnert via Python-ideas
On Aug 29, 2019, at 04:58, Steven D'Aprano wrote: > > - quote marks are also used for function calls, but only a limited > subset of function calls (those which take a single string literal > argument). This is a disingenuous argument. When you read spam.eggs, of course you know that that mea

[Python-ideas] Re: Custom string prefixes

2019-08-29 Thread Steven D'Aprano
On Wed, Aug 28, 2019 at 10:01:25PM -, stpa...@gmail.com wrote: > > you have something that looks like a kind of string czt'...' > > but is really a function call that might return absolutely > > anything at all; > > This is kinda the whole point. Yes, I understand that. And that's one of t

[Python-ideas] Re: Custom string prefixes

2019-08-29 Thread Greg Ewing
stpa...@gmail.com wrote: re'a|b|c' --becomes--> (locals()["re~"])("a|b|c") 2.3f --becomes--> (locals()["~f"])("2.3") How does one get a value into locals()["re~"]? -- Greg ___ Python-ideas mailing list -- python-ideas@python.org To

[Python-ideas] Re: Custom string prefixes

2019-08-29 Thread Paul Moore
On Thu, 29 Aug 2019 at 01:18, Andrew Barnert wrote: > > Also, it's worth noting that the benefits of *user-defined* literals > > are *not* the same as the benefits of things like 0.2f, or 3.14d, or > > even re/^hello.*/. Those things may well be useful. But the benefit > > you gain from *user-defi

[Python-ideas] Re: adding support for a "raw output" in JSON serializer

2019-08-29 Thread Antoine Pitrou
On Thu, 29 Aug 2019 12:51:04 +0900 "Stephen J. Turnbull" wrote: > > If there's a protocol for > converting objects to JSON, people will expect it to work, pretty much > as much as __str__ does, at least in the domain that they're working > in. And frequently it won't, and the user will be surpri