[Python-Dev] Re: Function Prototypes

2021-12-26 Thread Barry Scott


> On 26 Dec 2021, at 02:16, Steven D'Aprano  wrote:
> 
>> Hard enough that you really ought to help your reader out with a 
>> name,
> 
> What are you going to name it?
> 
>Int_and_Float_and_Int_returns_List_of_Int_Function
> 
> tells us nothing that
> 
>(int, float, int) -> list[int]
> 
>Callable[[int, float, int], list[int]]
> 
> doesn't already say.

It was said earlier in this thread that the naming should depend in the problem 
domain.

That name will not be as you suggest a long wordy thing but have a
name that is easier to understand.

So it might be CostFunction that would be a great name in that problem domain.

Barry

___
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-le...@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at 
https://mail.python.org/archives/list/python-dev@python.org/message/DKCKTY4TOKKI2IJNORX6RPT7XQF3GP7J/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-Dev] Re: issues-test-2 spam?

2021-12-26 Thread Ezio Melotti
Sorry, my mistake (again :)

As mentioned in an earlier python-dev thread, I'm working on the
bugs.python.org -> GitHub issues migration, and while testing I have
to delete and recreate the repo for each iteration.  Since the repo is
private, in order to get feedback from fellow core-devs and triagers,
I was adding both teams to the repo whenever I was recreating it, but
it turned out that was sending out email every time, so I stopped
adding the two teams.

However, I just checked that even after deleting and recreating the
repo, there are still 65 people that have access.  I just tried
deleting them individually and recreating the repo, but they are added
back automatically, and apparently get a notification like the ones
you have been seeing.

Since the python-core team has 110 members and only 65 people are
added automatically, I think it might depend on user-specific settings
(e.g. if you are a member of the python org and you are following it,
you might get automatically subscribed to every new org repo).

You can ignore/delete/filter those emails (and the ones from
issue-test-bpo), or you can try to unsubscribe/change the notification
settings and see if that works even after I delete and recreate the
repo.

Feel free to ping me directly (either via email or on discord) if you
have any issue/question/feedback, and sorry again for the noise.

--Ezio


On Sun, Dec 26, 2021 at 3:54 AM Steven D'Aprano  wrote:
>
> Apologies if this is the wrong place to raise this (where is the right
> place?) but over the last four days, I've received ten subscription
> notices for python/issues-test-2 on Github.
>
> Is anyone else also getting multiple subscription notices?
>
>
> --
> Steve
> ___
> Python-Dev mailing list -- python-dev@python.org
> To unsubscribe send an email to python-dev-le...@python.org
> https://mail.python.org/mailman3/lists/python-dev.python.org/
> Message archived at 
> https://mail.python.org/archives/list/python-dev@python.org/message/Q37XLFRF2H3OQFV55D7ASILCQ57XO6XE/
> Code of Conduct: http://python.org/psf/codeofconduct/
___
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-le...@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at 
https://mail.python.org/archives/list/python-dev@python.org/message/37WWZHAGQVRN354HCQFOEVECQALO472N/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-Dev] Re: Function Prototypes

2021-12-26 Thread Jim J. Jewett
Steven D'Aprano wrote:uble the size of Callable.
> > I think it takes only the characters needed to write the name IntToIntFunc.
> ... you may only use it once.

Could you provide an example where it is only used once?

The only way I can imagine is that you use it here when when defining your 
complicated function that takes a callback (once), but then you never actually 
call that complicated function, even from test code, nor do you expect your 
users to do so.

> The status quo is that we can use an anonymous type in the annotation 
> without pre-defining it, using Callable.

OK.  I'm not sure it would be a good idea, but we agree it is legal.

> PEP 677 proposes a new, more compact syntax for the same. 

Does it?  I agree that "(int, float) -> bool" is more compact than 
typing.Callable[...], but that feels like optimizing for the wrong thing.

I dislike the PEP's flat_map as an example, because it is the sort of 
infrastructure function that carries no semantic meaning, but ... I'll use it 
anyhow.

def flat_map(l, func):
out = []
for element in l:
out.extend(f(element))
return out


def wrap(x: int) -> list[int]:
return [x]

def add(x: int, y: int) -> int:
return x + y

It is reasonable to add a docstring to flat_map, but I grant that this doesn't 
work as well with tooling that might involve not actually seeing the function.

I agree that adding a long prefix of:

from typing import Callable

def flat_map(
l: list[int],
func: Callable[[int], list[int]]
) -> list[int]:

is undesirable.  But the biggest problem is not that "Callable..." has too many 
characters; the problem is that "Callable[[...], list[...]]" requires too many 
levels of sub-parsing. 

The PEP doesn't actually say what it proposes, [and you've suggested that my 
earlier attempt was slightly off, which may not bode well for likelihood of 
typos], but I'll *guess* that you prefer:

def flat_map(
l: list[int],
func: ((int) ->[int])
) -> list[int]:

which is slightly shorter physically, but not much simpler mentally.  It 
therefore creates an attractive nuisance.

def flat_map(
l: list[int],
func: wrap
) -> list[int]:

on the other hand, lets you read this definition without having to figure out 
what "wrap" does at the same time.  

"wrap" is a particularly bad example (because of the lack of semantic content 
in this example), but I think it still easily beats the proposed new solution, 
simply because it creates a "you don't need need to peer below this right now" 
barrier.


> Any proposal for function prototypes using 
> `def` is directly competing against Callable or arrow syntax for the 
> common case that we want an anonymous, unnamed type written in place.

I'm saying that catering to that "common" case is a trap, often leading you to 
a local optima that is bad globally.

> But if we can use an existing function as the prototype instead of 
> having to declare the prototype, that shifts the balance. 

I agree that re-using an existing function with the correct signature is 
better, *even* when that function doesn't make a good default.

...
> > I would say the opposite: most callback or key functions have very 
> simple signatures.
> If my function takes a key function, let's say:
> def spam(mylist:[str], 
>  a: int, 
>  b: float,
>  c: bool|None,
>  key: Callable[[str], str],
>  ) -> Eggs:
> mylist = sorted(mylist, key=key)
> ...
> the relevant signature is (str) -> str. Do we really need to give that a 
> predefined named prototype?
> def StrToStr(s: str) -> str: pass

If you really care about enforcing the str, then yes, it is worth saying

key: str_key

and defining str_key function as an example

def str_key(data:str)->str
return str(data)

> I would argue that very few people would bother. 

Because it would usually be silly to care that the list really contained 
strings, as opposed to "something sortable".  So if you do care, it is worth 
making your requirement stand out, instead of losing it in a pile of what looks 
like boilerplate.

-jJ
___
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-le...@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at 
https://mail.python.org/archives/list/python-dev@python.org/message/32QYLA7UFTC54UM3CO3REIH57WLLBL6H/
Code of Conduct: http://python.org/psf/codeofconduct/