[Python-ideas] Re: Confusing naming of Optional type should be changed

2022-07-12 Thread Kevin Mills
While confusion with optional arguments is somewhat unfortunate, the name came from an already established convention. A lot of languages have exactly the same concept, varying between names like Optional, Option, and Maybe. I don't think coming up with a Python-specific name for the same thing

[Python-ideas] Re: Add function for reading a specific number of bytes/characters from a file object that fails noisily

2022-03-03 Thread Kevin Mills
I actually initially was going to suggest a `strict` flag get added, but I figured that would be impractical. I was mostly concerned about classes that mimic file objects, because (obviously) their read methods wouldn't include a `strict` flag and you couldn't pass such objects to functions

[Python-ideas] Add function for reading a specific number of bytes/characters from a file object that fails noisily

2022-03-03 Thread Kevin Mills
The code I'm currently working on involves parsing binary data. If I ask for, say, 4 bytes, it's because I actually need 4 bytes and if the file doesn't have 4 bytes for me, it's malformed. Because `f.read(4)` can silently return less than 4 bytes and I don't want to have to explicitly double

[Python-ideas] Re: repeat until

2022-03-01 Thread Kevin Mills
If you don't like: while True: ... if whatever: break One thing I've seen people do is: condition = True while condition: ... condition = whatever You can use it if you really hate `while True` loops with `break`. ___

[Python-ideas] Re: __name__ for partial functions

2021-09-07 Thread Kevin Mills
I'm not sure what you're proposing. What should its `__name__` be set to? If you have a value you want its `__name__` to be, you can just set it yourself. ___ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to

[Python-ideas] Re: Allow starred expressions to be used as subscripts for nested lookups for getitem and setitem

2021-09-03 Thread Kevin Mills
As I said before, the "1,2,3" in `f(1,2,3)` has a very different meaning than the "1,2,3" in `d[1,2,3]`. One is a (comma-separated) list of expressions, and one is a single expression, a tuple. `*(1,2,3)` does not evaluate to the tuple `(1,2,3)`, so I don't think expecting it to do so in the

[Python-ideas] Re: Allow starred expressions to be used as subscripts for nested lookups for getitem and setitem

2021-09-03 Thread Kevin Mills
> One reason MRAB points to. The `*keys` syntax is more-or-less equivalent to > "substitute a tuple" in other Python contexts; you are proposing to give it a > completely different meaning. This would be confusing and inconsistent. I disagree that it is a completely different meaning. If the

[Python-ideas] Re: Allow starred expressions to be used as subscripts for nested lookups for getitem and setitem

2021-09-01 Thread Kevin Mills
No, definitely not. d[1,2,3] and d[1][2][3] are not the same thing. The latter is what I am talking about. ___ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org

[Python-ideas] Allow starred expressions to be used as subscripts for nested lookups for getitem and setitem

2021-09-01 Thread Kevin Mills
Given code like this: ``` d = {1: {2: {3: 4}}} print(d[1][2][3]) d[1][2][3] = None print(d) ``` It should be possible to rewrite it using a starred expression, like this: ``` d = {1: {2: {3: 4}}} keys= 1,2,3 print(d[*keys]) d[*keys] = None print(d) ``` Hopefully it's clear from that example

[Python-ideas] Re: Method to efficiently advance iterators for sequences that support random access

2020-10-06 Thread Kevin Mills
Sorry for the duplicate message. I realized two seconds after I sent it, that I only replied to you and not the group. I didn't see the `consume` recipe until after I posted, or I probably would've mentioned it. What I want would have to be done in C, because `it_index` (as `listiterobject`

[Python-ideas] Method to efficiently advance iterators for sequences that support random access

2020-10-05 Thread Kevin Mills
str_iterator, bytes_iterator, range_iterator, list_iterator, and tuple_iterator (and probably others) should have a method that is capable of efficiently advancing the iterator, instead of having to call next repeatedly. I suggest adding an itertools.advance function which dispatches to a