[Python-ideas] Re: shouldn't slices be iterable ?
On Fri, Mar 19, 2021 at 3:18 PM Cameron Simpson wrote: > > I whinged: > >> On Fri, Mar 19, 2021 at 10:46 AM Cameron Simpson wrote: > >> > I know that range(start,end,stride) will produce what I'd want from > >> > iter(slice(start,end,stride)), but wouldn't it be reasonable for a slice > >> > itself to be iterable? [...] > > >On Thu, Mar 18, 2021 at 6:09 PM Chris Angelico > >wrote: > >> What if the start is positive and the end is negative? What values should > >> i get? > > On 18Mar2021 19:15, Caleb Donovick wrote: > >Or perhaps more problematic what happens if only stride is specified? > > I'd be happy if the behaviour were the same as range(), yea even to > being a concise way to spell range(slice.start,slice.end,slide.stride); > who wants to say that if iter(slice) means the same thing? > > For only stride, ValueError. For positive stride and start > end, empty > iteration. > Have you considered range(*slice.indices(len)) ? You need to provide a length in order for negative or omitted endpoints to make sense, but otherwise it's the same idea. But it's difficult to do that within iteration protocol, as there's no way to provide that all-important length. ChrisA ___ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/64CGSN23LBRZETQKS6GF35VCSVROE6WM/ Code of Conduct: http://python.org/psf/codeofconduct/
[Python-ideas] Re: shouldn't slices be iterable ?
I whinged: >> On Fri, Mar 19, 2021 at 10:46 AM Cameron Simpson wrote: >> > I know that range(start,end,stride) will produce what I'd want from >> > iter(slice(start,end,stride)), but wouldn't it be reasonable for a slice >> > itself to be iterable? [...] >On Thu, Mar 18, 2021 at 6:09 PM Chris Angelico >wrote: >> What if the start is positive and the end is negative? What values should >> i get? On 18Mar2021 19:15, Caleb Donovick wrote: >Or perhaps more problematic what happens if only stride is specified? I'd be happy if the behaviour were the same as range(), yea even to being a concise way to spell range(slice.start,slice.end,slide.stride); who wants to say that if iter(slice) means the same thing? For only stride, ValueError. For positive stride and start > end, empty iteration. Cheers, Cameron Simpson ___ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/CKYOIISUXXV3SCSFQFWQYENED3GQU2L6/ Code of Conduct: http://python.org/psf/codeofconduct/
[Python-ideas] Re: shouldn't slices be iterable ?
Or perhaps more problematic what happens if only stride is specified? On Thu, Mar 18, 2021 at 6:09 PM Chris Angelico wrote: > On Fri, Mar 19, 2021 at 10:46 AM Cameron Simpson wrote: > > > > I know that range(start,end,stride) will produce what I'd want from > > iter(slice(start,end,stride)), but wouldn't it be reasonable for a slice > > itself to be iterable? > > > > Yes, only one obvious way and all that, but inside eg __getitem__ it > > seems to me that: > > > > if isinstance(index, slice): > > for i in index: > > ... do stuff with i ... > > > > is the obvious thing to do. > > > > What if the start is positive and the end is negative? What values should > i get? > > ChrisA > ___ > Python-ideas mailing list -- python-ideas@python.org > To unsubscribe send an email to python-ideas-le...@python.org > https://mail.python.org/mailman3/lists/python-ideas.python.org/ > Message archived at > https://mail.python.org/archives/list/python-ideas@python.org/message/O6ZF3UZIWTJFBGOYDXDZ7X4X7FA6DNHK/ > Code of Conduct: http://python.org/psf/codeofconduct/ > ___ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/ZRAV5SGWHTLLRZF5KDA5244CPHHQY34F/ Code of Conduct: http://python.org/psf/codeofconduct/
[Python-ideas] Re: shouldn't slices be iterable ?
On Fri, Mar 19, 2021 at 10:46 AM Cameron Simpson wrote: > > I know that range(start,end,stride) will produce what I'd want from > iter(slice(start,end,stride)), but wouldn't it be reasonable for a slice > itself to be iterable? > > Yes, only one obvious way and all that, but inside eg __getitem__ it > seems to me that: > > if isinstance(index, slice): > for i in index: > ... do stuff with i ... > > is the obvious thing to do. > What if the start is positive and the end is negative? What values should i get? ChrisA ___ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/O6ZF3UZIWTJFBGOYDXDZ7X4X7FA6DNHK/ Code of Conduct: http://python.org/psf/codeofconduct/
[Python-ideas] shouldn't slices be iterable ?
I know that range(start,end,stride) will produce what I'd want from iter(slice(start,end,stride)), but wouldn't it be reasonable for a slice itself to be iterable? Yes, only one obvious way and all that, but inside eg __getitem__ it seems to me that: if isinstance(index, slice): for i in index: ... do stuff with i ... is the obvious thing to do. Cheers, Cameron Simpson ___ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/F27M57MIYIDD55YVASYGVOU3LSKN74S7/ Code of Conduct: http://python.org/psf/codeofconduct/
[Python-ideas] Re: self documenting kwarg passing in functions similar to f-strings in python3.8
There was a long discussion about a year ago: https://mail.python.org/archives/list/python-ideas@python.org/thread/SIMIOC7OW6QKLJOTHJJVNNBDSXDE2SGV/#N2ZY5NQ5T2OJRSUGZJOANEQOGEQIYYIK Eric On 3/18/2021 12:28 AM, alexei.ciob...@adelaide.edu.au wrote: Hi all, Not sure if this feature already exists in python or if it has been proposed already but it would be extremely helpful for me and doesn't seem too difficult to implement. I often write functions with really long kwarg names that call other functions that share a kwarg name. What I currently have is something like (very simplified example) def function1(x, y, some_really_long_kwarg=True, **kwargs): other_kwarg = x>y function2(x, y, some_really_long_kwarg=some_really_long_kwarg, other_kwarg=other_kwarg) return What I would like is to be able to write something like def function1(x, y, some_really_long_kwarg=True, **kwargs): other_kwarg = x>y function2(x, y, some_really_long_kwarg=, other_kwarg=) return where the kwarg= behaves similarly to how it does for f-strings in python3.8 when you write something like f'{other_kwarg=}' ___ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/AOWAHGWQQYOSPYBOUOFDIGDMAVUXSYSO/ Code of Conduct: http://python.org/psf/codeofconduct/ -- Eric V. Smith ___ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/GYT4GUOUBOTTMWMLP2UCA5IOXV3M3XX4/ Code of Conduct: http://python.org/psf/codeofconduct/
[Python-ideas] self documenting kwarg passing in functions similar to f-strings in python3.8
Hi all, Not sure if this feature already exists in python or if it has been proposed already but it would be extremely helpful for me and doesn't seem too difficult to implement. I often write functions with really long kwarg names that call other functions that share a kwarg name. What I currently have is something like (very simplified example) def function1(x, y, some_really_long_kwarg=True, **kwargs): other_kwarg = x>y function2(x, y, some_really_long_kwarg=some_really_long_kwarg, other_kwarg=other_kwarg) return What I would like is to be able to write something like def function1(x, y, some_really_long_kwarg=True, **kwargs): other_kwarg = x>y function2(x, y, some_really_long_kwarg=, other_kwarg=) return where the kwarg= behaves similarly to how it does for f-strings in python3.8 when you write something like f'{other_kwarg=}' ___ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/AOWAHGWQQYOSPYBOUOFDIGDMAVUXSYSO/ Code of Conduct: http://python.org/psf/codeofconduct/
[Python-ideas] Improve the textual representation of IPv4-mapped IPv6 addresses
Hi, Python supports IPv4-mapped IPv6 addresses as defined by RFC 4038: "the IPv6 address :::x.y.z.w represents the IPv4 address x.y.z.w.” The current behavior is as follows: from ipaddress import ip_address addr = ip_address(':::8.8.4.4') # IPv6Address(':::808:404') addr.ipv4_mapped # IPv4Address('8.8.4.4') Note that the textual representation of the IPv6Address is *not* in IPv4-mapped format. It prints :::808:404 instead of :::8.8.4.4. This is technically correct, but it’s somewhat frustrating as it makes it harder to read IPv4s embedded in IPv6 addresses. My proposal would be to check, in __str__, if an IPv6 is an IPv4-mapped, and to return the appropriate representation : from ipaddress import ip_address addr = ip_address(':::8.8.4.4') # Current behavior str(addr) # ':::808:404' repr(addr) # IPv6Address(':::808:404') # Proposed behavior str(addr) # ':::8.8.4.4' repr(addr) # IPv6Address(':::8.8.4.4') A few data points: - Julia prints :::808:404 (current behavior) - C (glibc) and ClickHouse prints :::8.8.4.4 (proposed behavior) Any thoughts? Maxime ___ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/T7FN2PMPNY5E5234ZNL4BAEYVJFKPE4U/ Code of Conduct: http://python.org/psf/codeofconduct/