[Python-ideas] Re: Standard tool for iterating over recursive data structures?

2021-01-01 Thread Samuel Freilich via Python-ideas
Interesting to look at the code for some of this. list.repr and dict.repr seem to be taking the "construct a set of seen items" approach. Except it's not using a set of ids, it's doing a linear pass over a list of visited PyObjects each time (which seems somewhat surprising to me, though it's only

[Python-ideas] Re: startswith() and endswith() methods returning the matched value

2021-08-09 Thread Samuel Freilich via Python-ideas
> that can be used (eg) for indexing Even without it being used in as complicated a way as that it's *still* not backward compatible because of the trivial case, as foo.endswith("") is True. On Sun, Aug 8, 2021 at 11:55 PM Chris Angelico wrote: > On Mon, Aug 9, 2021 at 1:42 PM wrote: > > > > T

[Python-ideas] Re: startswith() and endswith() methods returning the matched value

2021-08-09 Thread Samuel Freilich via Python-ideas
I was just saying that using the bool return value as an index is a bit obscure, compared to using it as a condition in an if statement. But even in the more common use, returning the matched string is still a chance in behavior. On Mon, Aug 9, 2021, 10:13 AM Chris Angelico wrote: > On Tue, Aug

[Python-ideas] Improved Error Message for "Unhashable Type"

2020-09-28 Thread Samuel Freilich via Python-ideas
The error message for using a mutable sequence as a set item or map key seems to frequently confuse Python beginners. The current wording is: >>> {[1, 2, 3]: [4, 5, 6]} TypeError: unhashable type: 'list' The first thing a Google search finds for "unhashable type" is ~4k Stack Overflow results lik

[Python-ideas] Re: Improved Error Message for "Unhashable Type"

2020-09-28 Thread Samuel Freilich via Python-ideas
sion. I do think it can be useful to have more direct links to documentation, though. > at least add "unhashable" to the glossary -- after all, both "mutable" and "immutable" are in there. I think that's reasonable. On Mon, Sep 28, 2020 at 11:41 AM Christophe

[Python-ideas] Re: execute function on iterator items without changing or consuming iterator

2020-10-25 Thread Samuel Freilich via Python-ideas
This seems like it might be a reasonable thing to have in intertools? It's not hard to write this sort of thing with map: some_iter = map(lambda x: (print(x), x)[1], some_iter) But it's a little awkward. (Though maybe I'm missing a less awkward way to do that.) Java has Stream.peek for similar f

[Python-ideas] Reconstructing datetime from microsecond timestamp

2023-09-24 Thread Samuel Freilich via Python-ideas
datetime.datetime has microsecond precision, and if you want to reconstruct a datetime from microseconds since the Unix epoch in a provided timezone, you can do: (datetime(1970, 1, 1, tzinfo=timezone.utc) + timedelta(microseconds=timestamp_us)).astimezone(tz) This is a general solution, but it co

[Python-ideas] Re: Reconstructing datetime from microsecond timestamp

2023-09-25 Thread Samuel Freilich via Python-ideas
p> wrote: > Samuel Freilich via Python-ideas writes: > > > This might all be too much thought about edge cases that don't > > matter, but given the *_ns() functions in the time module (PEP > > 564), I'm curious why datetime doesn't have a constructor