[Python-ideas] Re: C#-style "as" casting syntactic sugar for type hints

2023-03-23 Thread Damian Shaw
But doesn't date.strftime returns str not Any: https://github.com/python/typeshed/blob/main/stdlib/datetime.pyi#L75 ? Damian On Thu, Mar 23, 2023 at 10:00 PM Will Bradley wrote: > This is some real code I wrote the other day: > payload = { > "birthDate": str(date.strftime('%m/%d/%Y')), > ... >

[Python-ideas] Re: A modulo operator consistent with euclidean division.

2022-03-18 Thread Damian Shaw
Can you give some examples of how it would be used differently than the current modulo operator and what value it would bring? For those who have not taken number theory courses in a long time (or never!) it's not clear how this would be useful for Python. Damian (he/him) On Fri, Mar 18, 2022

[Python-ideas] Re: Make 10**400 / 1e200 work?

2022-02-19 Thread Damian Shaw
That sounds like a lot of extra checks to put on "/" when the error message is clear and the user could implement their own checks if they are running into this niche use case and do 10**400 / int(1e200). Damian (he/him) On Sat, Feb 19, 2022 at 8:36 AM Stefan Pochmann wrote: > It crashes

[Python-ideas] Re: Missing expandvars equivalent in pathlib

2022-02-10 Thread Damian Shaw
FYI there was a patch for this in the past and it was rejected: https://bugs.python.org/issue21301 Damian (he/him) On Thu, Feb 10, 2022 at 12:04 PM Christopher Barker wrote: > +1 -- I would really like pathlib to be able to used for everything one > would need to do with paths. > > -CHB > > >

[Python-ideas] Re: Adding sortedconatiners to Python or merge the ideas?

2022-02-03 Thread Damian Shaw
This was very recently discussed at length: https://mail.python.org/archives/list/python-...@python.org/thread/YB2JD477TKPB2HTXDW6ZXUBD6NFFFHHJ/#YB2JD477TKPB2HTXDW6ZXUBD6NFFFHHJ Damian (he/him) On Thu, Feb 3, 2022 at 11:51 AM Abdur-Rahmaan Janhangeer < arj.pyt...@gmail.com> wrote: > Greetings,

[Python-ideas] Re: Shorthand syntax for lambda functions that have a single parameter

2021-09-29 Thread Damian Shaw
I find this approach too cryptic compared to reading regular Python notation, my brain has to mode switch to make sense of it. Would a little extra ?: be too much add to make clear it's a lambda function, e.g. ?: ? > 0 instead of ? > 0 Also either approach *could *add multi-argument lambdas: ?1,

[Python-ideas] Re: A better math.factorial

2021-09-16 Thread Damian Shaw
Is there a reason you defined it as n * math.gamma(n), instead of math.gamma(n+1)? Damian (he/him) On Thu, Sep 16, 2021 at 2:35 PM Jonatan wrote: > Currently, math.factorial only supports integers and not floats, whereas > the "mathematical" version supports both integers and floats. > I.e: >

[Python-ideas] Re: Template Literals for Python (easy and save creation of HTML)

2021-09-03 Thread Damian Shaw
I am not convinced of tying `backticks` for a single markup language. Different markup languages presumably have different escape methods? Is Python supposed to be explicitly an HTML based language like many of the design choices of JavaScript? It also seems like a lot to ask to introduce yet

[Python-ideas] Re: Proposal: Python Native bindings for OpenAPI

2021-08-06 Thread Damian Shaw
In your code example it looks like FastAPI is making 1 HTTP request vs. your library is making 3 HTTP requests? Or are there some missing lines? Or am I missing something? Also are you referring to https://github.com/pyopenapi/pyopenapi ? And if so what would be the reasoning to pull something

[Python-ideas] Re: Deprecate sum of lists

2021-06-18 Thread Damian Shaw
Is there somewhere where you can use "*ab" but not "a ,b" currently in Python? On Fri, Jun 18, 2021 at 11:43 AM Mathew Elman wrote: > I don't see how allowing > > [x, y for x in a] > > follows from allowing > > [*chunk for chunk in list_of_lists]. >

[Python-ideas] Re: The Pattern Matching Wildcard Is A Bad Idea

2021-06-02 Thread Damian Shaw
that runs in a shell to behave the same in a script, and > vice-versa. But, if `_` is both a variable (shell) and a keyword (`match`), > that 's not the case. You have to work around the problem, e.g. by > reaffecting `_`. > My fear is that most people (me included) will most likely forget this

[Python-ideas] Re: Introduce constants in Python (constant name binding)

2021-05-25 Thread Damian Shaw
It's still a Python feature even if it's not a language feature, it's well defined by PEP and any type checker wanting to implement type hinting to spec must include it. Further type hinting allows developers who want to use a Constant / Final feature get the benefit already from type hinting,

[Python-ideas] Re: New Idea: A safe keyword to execute the following statement in a failsafe mode.

2021-05-23 Thread Damian Shaw
FYI, Something very similar already exists in the standard library, contextlib.suppress: https://docs.python.org/3/library/contextlib.html#contextlib.suppress It makes a nice 2+ liner for a lot of situations: with suppress(Exception): ... Seems more flexible than OPs keyword suggestion as

[Python-ideas] Re: Accepting a function argument of a particular type specified by the user

2021-04-25 Thread Damian Shaw
Typeguard provides this functionality: https://typeguard.readthedocs.io/en/latest/userguide.html It's not perfect but that's because runtime type hints have lots of restrictions on what can be reasoned about them. But for simple and common cases it works very well. -- Damian (he / him) On Sun,