[Python-ideas] Re: Optional keyword arguments

2020-05-29 Thread Stephen J. Turnbull
Greg Ewing writes: > To my mind, the signature consists of information that a > static type checker would need to verify that a call is valid. > That does not include default values of arguments. That's a parsimonious and reasonable definition, and the one historically used by Emacs Lisp. But

[Python-ideas] Re: Python __main__ function

2020-05-29 Thread Paul Moore
Also, I routinely write scripts that have no `if __name__ == '__main__'` line at all, they just run - no-one should ever import them, so it makes no difference. And I exit (in multiple places) using `raise SystemExit("reason")`. My point being that yes, there are *lots* of ways of writing Python s

[Python-ideas] Re: An HTTP API to list versions of Python

2020-05-29 Thread M.-A. Lemburg
Since cutting releases is done by the release manager, producing such meta would have to be part of his or her role. The tools RMs use are here: https://github.com/python/release-tools/ The PEP describing the process: https://www.python.org/dev/peps/pep-0101/ Looking through the release.py scrip

[Python-ideas] Expose PyFloat_AsDouble to Python

2020-05-29 Thread Mark Dickinson
Here's the short version: * "Convert float-like object to a float" is a useful operation * For a C extension, there's an obvious way to spell that operation: use `PyFloat_AsDouble` * In pure Python, there's no Obvious Way To Do It * Proposal: expose the equivalent of `PyFloat_FromDouble(PyFloat_

[Python-ideas] Re: Expose PyFloat_AsDouble to Python

2020-05-29 Thread Serhiy Storchaka
29.05.20 12:48, Mark Dickinson пише: 2. Call the object's `__float__` method. But this is fraught with peril, too: for a proper equivalent, you need to be careful to look up `__float__` on the type, not the object itself. And then a new version of Python changes `PyFloat_AsDouble` to also acce

[Python-ideas] Re: Optional keyword arguments

2020-05-29 Thread Steven D'Aprano
On Fri, May 29, 2020 at 12:36:20PM +1200, Greg Ewing wrote: > On 29/05/20 12:17 am, Richard Damon wrote: > >But default values for arguments are really part of the responsibility > >for the caller, not the called function. The classic implementation > >would be that the caller passes all of the exp

[Python-ideas] Re: Optional keyword arguments

2020-05-29 Thread Steven D'Aprano
On Thu, May 28, 2020 at 12:11:38PM +0200, Alex Hall wrote: > Consider this code: > > ``` > x = 1 > > def foo(): > print(x) > x = 2 > > foo() > ``` > > Here `print(x)` doesn't print '1', it gives `UnboundLocalError: local > variable 'x' referenced before assignment`. It knows that `x` i

[Python-ideas] Re: Optional keyword arguments

2020-05-29 Thread Steven D'Aprano
On Thu, May 28, 2020 at 08:04:07PM +1000, Chris Angelico wrote: > On Thu, May 28, 2020 at 8:01 PM Steven D'Aprano wrote: > > > > On Wed, May 27, 2020 at 05:03:09AM +1000, Chris Angelico wrote: > > > > > def foo(): > > > if False: x = 0 > > > # what is x now? > > > > > > There is no *value*

[Python-ideas] Re: Optional keyword arguments

2020-05-29 Thread Chris Angelico
On Fri, May 29, 2020 at 10:51 PM Steven D'Aprano wrote: > > On Thu, May 28, 2020 at 08:04:07PM +1000, Chris Angelico wrote: > > If it's a > > language feature, then the name 'x' must be in the state of "local > > variable without a value". > > Oh ho, I see what you are doing now :-) > > I'm going

[Python-ideas] Re: Expose PyFloat_AsDouble to Python

2020-05-29 Thread Antoine Pitrou
On Fri, 29 May 2020 09:48:53 - "Mark Dickinson" wrote: > > I have a proof-of-concept PR [1] that exposes this in the `operator` module > as `operator.as_float`. See also the discussion on the tracker [2]. `operator.as_float` sounds good to me. There's the `operator.index` precedent. Regar

[Python-ideas] Re: Python GIL Thoughts

2020-05-29 Thread redradist
Yesterday RustPython team finished threading without GIL: https://github.com/RustPython/RustPython/issues/1831 ___ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.o

[Python-ideas] datetime.time input restrictions

2020-05-29 Thread Ben Axelrod
I was wondering why have restrictions on the datetime.time constructor arguments? For example, why can't you enter 1.5 minutes or 90 seconds to create a datetime object with 1 minute and 30 seconds? >>> datetime.time(minute=1.5) Traceback (most recent call last): File "", line 1, in TypeError:

[Python-ideas] Re: Expose PyFloat_AsDouble to Python

2020-05-29 Thread Serhiy Storchaka
29.05.20 14:22, Serhiy Storchaka пише: I prefer it to be an alternative float constructor. We can also add the corresponding constructor for complex, and add constructors which accept only str, bytes or bytes-like object (i.e. parse a text representation of the number). See also previous discus

[Python-ideas] Re: Optional keyword arguments

2020-05-29 Thread Dominik Vilsmeier
On 29.05.20 15:09, Chris Angelico wrote: On Fri, May 29, 2020 at 10:51 PM Steven D'Aprano wrote: On Thu, May 28, 2020 at 08:04:07PM +1000, Chris Angelico wrote: If it's a language feature, then the name 'x' must be in the state of "local variable without a value". Oh ho, I see what you are d

[Python-ideas] Re: Python __main__ function

2020-05-29 Thread David Mertz
I agree with Paul's sentiment. We do not need to bless just one way of writing scripts. Code review or organization style guides, sure. But not at language level. I also write scripts with no explicit __main__. But I rarely name them as .py. In the style of Unix commands, they have no extension, b

[Python-ideas] Re: datetime.time input restrictions

2020-05-29 Thread Chris Angelico
On Sat, May 30, 2020 at 12:57 AM Ben Axelrod wrote: > > I was wondering why have restrictions on the datetime.time constructor > arguments? For example, why can't you enter 1.5 minutes or 90 seconds to > create a datetime object with 1 minute and 30 seconds? > > >>> datetime.time(minute=1.5) >

[Python-ideas] Re: Python GIL Thoughts

2020-05-29 Thread MRAB
On 2020-05-29 15:19, redrad...@gmail.com wrote: Yesterday RustPython team finished threading without GIL: https://github.com/RustPython/RustPython/issues/1831 That first example is Python 2... ___ Python-ideas mailing list -- python-ideas@python.

[Python-ideas] Re: Optional keyword arguments

2020-05-29 Thread Alex Hall
On Fri, May 29, 2020 at 2:18 PM Steven D'Aprano wrote: > On Thu, May 28, 2020 at 12:11:38PM +0200, Alex Hall wrote: > > > Consider this code: > > > > ``` > > x = 1 > > > > def foo(): > > print(x) > > x = 2 > > > > foo() > > ``` > > > > Here `print(x)` doesn't print '1', it gives `UnboundL

[Python-ideas] Re: Optional keyword arguments

2020-05-29 Thread David Mertz
On Fri, May 29, 2020 at 3:19 AM Stephen J. Turnbull < turnbull.stephen...@u.tsukuba.ac.jp> wrote: > # Just too ugly for me! > def foo(x=lambda: random.randint(0,9)): > > x = x() > # ... > I think this is a perfect example of where my desired "delayed" (or "deferred") const

[Python-ideas] Re: Optional keyword arguments

2020-05-29 Thread Alex Hall
On Fri, May 29, 2020 at 7:05 PM David Mertz wrote: > On Fri, May 29, 2020 at 3:19 AM Stephen J. Turnbull < > turnbull.stephen...@u.tsukuba.ac.jp> wrote: > >> # Just too ugly for me! >> def foo(x=lambda: random.randint(0,9)): >> >> x = x() >> # ... >> > > I think this is a

[Python-ideas] Re: Optional keyword arguments

2020-05-29 Thread David Mertz
> > Where do we draw the line? How much of the behaviour of the > > function do we want to move into the header? > > Well obviously we don't draw the line until we've fallen down the > slippery slope and the entire body of the function is part of the > header! > Sure, what's the problem? :-) def

[Python-ideas] Re: Optional keyword arguments

2020-05-29 Thread David Mertz
On Fri, May 29, 2020 at 1:12 PM Alex Hall wrote: > def foo(a=17, b=42,, x=delayed randint(0,9), y=delayed randrange(1,100)): > >> if something: >> # The simple case is realizing a direct delayed >> val = concretize x >> elif something_else: >> # This line creates a

[Python-ideas] Re: Optional keyword arguments

2020-05-29 Thread Rhodri James
On 29/05/2020 18:02, David Mertz wrote: I think this is a perfect example of where my desired "delayed" (or "deferred") construct would be great. There are lots of behaviors that I have not thought through, and do not specify here. But for example: def foo(a=17, b=42,, x=delayed randint(0,9),

[Python-ideas] Re: Python GIL Thoughts

2020-05-29 Thread Paul Sokolovsky
Hello, On Fri, 29 May 2020 14:19:40 - redrad...@gmail.com wrote: > Yesterday RustPython team finished threading without GIL: > https://github.com/RustPython/RustPython/issues/1831 So what? As was pointed out, there're bunch of Python implementations which don't use GIL. And it's very eas

[Python-ideas] Delayed computation

2020-05-29 Thread David Mertz
On Fri, May 29, 2020 at 1:56 PM Rhodri James wrote: > Presumably "delayed" is something that would be automatically applied to > the actual parameter given, otherwise your call graphs might or might > not actually be call graphs depending on how the function was called. > What happens if I call "

[Python-ideas] Re: Python GIL Thoughts

2020-05-29 Thread tritium-list
> -Original Message- > From: Paul Sokolovsky > Sent: Friday, May 29, 2020 2:26 PM > To: redrad...@gmail.com > Cc: python-ideas@python.org > Subject: [Python-ideas] Re: Python GIL Thoughts > > Hello, > > On Fri, 29 May 2020 14:19:40 - > redrad...@gmail.com wrote: > > > Yesterday R

[Python-ideas] Re: Python GIL Thoughts

2020-05-29 Thread Paul Sokolovsky
Hello, On Fri, 29 May 2020 14:44:40 -0400 wrote: [] > These are things that a runtime implementer has to decide on. These > are also thing that a runtime use gets to complain about. "Don't > share data amongst threads" is not advice to the cpython user to get > truly parallel thread execution

[Python-ideas] Re: Python GIL Thoughts

2020-05-29 Thread redradist
I've just share information, relax ;) And also it seems like they have very low overhead with atomic variables Arc ___ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.

[Python-ideas] Re: Delayed computation

2020-05-29 Thread Dominik Vilsmeier
On 29.05.20 20:38, David Mertz wrote: On Fri, May 29, 2020 at 1:56 PM Rhodri James mailto:rho...@kynesim.co.uk>> wrote: Presumably "delayed" is something that would be automatically applied to the actual parameter given, otherwise your call graphs might or might not actually be

[Python-ideas] Advanced Debugger Support C-API is incomplete?

2020-05-29 Thread Andrew Pashkin
I want to implement my own version of _PyThread_CurrentFrames() , but it seems like it's not possible using public C-API. The comment

[Python-ideas] Re: Delayed computation

2020-05-29 Thread David Mertz
On Fri, May 29, 2020 at 5:06 PM Dominik Vilsmeier wrote: > I'm still struggling to imagine a real use case which can't already be > solved by generators. Usually the purpose of such computation graphs is to > execute on some specialized hardware or because you want to backtrack > through the grap

[Python-ideas] Re: Optional keyword arguments

2020-05-29 Thread Steven D'Aprano
On Fri, May 29, 2020 at 04:52:38PM +0200, Dominik Vilsmeier wrote: > Indeed locals are special, but why was it designed this way? Why not > resolve such an unbound local name in the enclosing scopes? Probably for speed. When I first learned about the LGB rule (so long ago there wasn't even an E

[Python-ideas] Re: Optional keyword arguments

2020-05-29 Thread Steven D'Aprano
On Fri, May 29, 2020 at 06:03:30PM +0200, Alex Hall wrote: > > I never said that Python's scoping rules were implementation details. > > > > I said that the storage mechanism of *how* local variables are stored, > > and hence whether or not writes to `locals()` are reflected in the > > local varia

[Python-ideas] Re: Optional keyword arguments

2020-05-29 Thread Greg Ewing
On 29/05/20 11:49 pm, Steven D'Aprano wrote: Where else would you put the parameter defaults, if not in the parameter list? In some part of the function that's not the parameter list. :-) There are many ways it could be done. I've suggested one already (a special assignment statement). Anothe

[Python-ideas] Re: Optional keyword arguments

2020-05-29 Thread Greg Ewing
On 30/05/20 12:11 am, Steven D'Aprano wrote: I said that the storage mechanism of *how* local variables are stored, and hence whether or not writes to `locals()` are reflected in the local variables, is an implementation detail. That's true, but just to be clear, my ?= idea doesn't rely on that

[Python-ideas] Re: Optional keyword arguments

2020-05-29 Thread Steven D'Aprano
Attempting to bring things back on topic to function parameters with late binding. On Fri, May 29, 2020 at 06:03:30PM +0200, Alex Hall wrote: > Chris was just saying that a statement like `x ?= y` meaning 'assign the > value of y to the local variable x if x is currently unbound' already fits >

[Python-ideas] Re: Optional keyword arguments

2020-05-29 Thread Greg Ewing
On 30/05/20 2:52 am, Dominik Vilsmeier wrote: Indeed locals are special, but why was it designed this way? Why not resolve such an unbound local name in the enclosing scopes? From experience with other languages I can attest that "sometimes local, sometimes global depending on what gets execute