[Python-ideas] Re: Deprecate/change the behaviour of ~bool

2021-02-22 Thread Josh Rosenberg
> You could write it as a ^ (not b), as long as you don't mind it giving back an integer rather than a bool. Actually, that'll give back a bool if a is a bool (and (not b) produces a bool); ^ is overridden for bool/bool operations and itself returns a bool. On Tue, Feb 23, 2021 at 1:48 AM Chris A

Re: [Python-ideas] PEP: Dict addition and subtraction

2019-03-05 Thread Josh Rosenberg
s, and the semi-lossy rules of unioning make more sense there); it would also make - make sense, since + is only matched by - in numeric contexts; on collections, | and - are paired. And I consider the - functionality the most useful part of this whole proposal (because I *

Re: [Python-ideas] PEP: Dict addition and subtraction

2019-03-05 Thread Josh Rosenberg
On Wed, Mar 6, 2019 at 12:08 AM Guido van Rossum wrote: > On Tue, Mar 5, 2019 at 3:50 PM Josh Rosenberg < > shadowranger+pythonid...@gmail.com> wrote: > >> >> On Tue, Mar 5, 2019 at 11:16 PM Steven D'Aprano >> wrote: >> >>> On Sun, Mar 03,

Re: [Python-ideas] PEP: Dict addition and subtraction

2019-03-06 Thread Josh Rosenberg
that don't adhere to these semantics. It's that adding yet a third meaning to + (and it is a third meaning; it has no precedent in any existing type in Python, nor in any other major language; even in the minor languages that allow it, they use + for sets as well, so Python using + is

Re: [Python-ideas] PEP: Dict addition and subtraction

2019-03-06 Thread Josh Rosenberg
t rules of any other language except by coincidence). a winning on order and b winning on value is a historical artifact of how Python's dict developed; I doubt any other language would intentionally choose to split responsibility like that if they weren't handcuffed by

Re: [Python-ideas] More alternate constructors for builtin type

2019-05-06 Thread Josh Rosenberg
The other bytes object constructor I often find myself in need of without being able to remember how to do it is creating a a length 1 bytes object from a known ordinal. The "obvious": someordinal = ... bytes(someordinal) creates a zeroed bytes of that length, which is clearly wrong. I eventuall

Re: [Python-ideas] More alternate constructors for builtin type

2019-05-06 Thread Josh Rosenberg
bytes.ord is a bad name, given the behavior would be the opposite of ord (ord converts length one str to int, not int to length one str). PEP467 (currently deferred to 3.9 or later) does have proposals for this case, either bytes.byte (old proposal: https://legacy.python.org/dev/peps/pep-0467/#add

[Python-ideas] Re: For-expression/throwaway comprehension

2019-07-26 Thread Josh Rosenberg
On Fri, Jul 26, 2019 at 10:06 PM Kyle Stanley wrote: > From my understanding, consume() effectively provides the functionality the > author was looking for. Also, between the options of `for _ in iter:` vs > `colllections.deque(it, maxlen=0)`, how significant is the performance > difference? > >

[Python-ideas] Re: PEP 584: Add + and += operators to the built-in dict class.

2019-10-17 Thread Josh Rosenberg
Notes on new PEP: The section on {**d1, **d2} claims "It is only guaranteed to work if the keys are all strings. If the keys are not strings, it currently works in CPython, but it may not work with other implementations, or future versions of CPython[2]." That's 100% wrong. You're mixing up the

[Python-ideas] Re: Argumenting in favor of first()

2019-12-05 Thread Josh Rosenberg
"Also, the for-loop version quits the moment it finds a Product type, while the `first` version has to first process the entire jsonld_items structure." The first version doesn't have to process the whole structure; it's written with a generator expression, so it only tests and produces values on

[Python-ideas] Re: Compound statement colon (Re: Re: Improve SyntaxError for obvious issue:)

2020-01-17 Thread Josh Rosenberg
The colon remains syntactically necessary in some cases, particularly to disambiguate cases involving one-lining (no block involved). Stupid example: If the colon is optional, what does: if d +d mean? Is it a test of the value of d, followed by invoking the unary plus operator as a one-liner (tha

[Python-ideas] Re: str(obj) not calling obj.__str__?

2020-02-22 Thread Josh Rosenberg
This is explained in "Special Method Lookup": https://docs.python.org/3/reference/datamodel.html#special-method-lookup Short version: For both correctness and performance, special methods (those that begin and end with double underscores) are typically looked up on the class, not the instance. If

[Python-ideas] Re: Curious : Why staticmethod if classmethods can do everything a static method can?

2020-09-13 Thread Josh Rosenberg
The immediate use case I can think of this for is to make it possible to just do: __len__ = instancemethod(operator.attrgetter('_length')) __hash__ = instancemethod(operator.attrgetter('_cached_hash')) and stuff like that. Mostly just a minor performance optimization to avoid the overhead of Pyth

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

2020-10-06 Thread Josh Rosenberg
This: def advance(it, n): try: return it[n:] except TypeError: return itertools.islice(it, n, None) has the disadvantages of: 1. Requiring a temporary copy of the data sliced (if len(it) is 1_000_000, and n is 500_000, you're stuck between 500_000 pointless __next__ calls

[Python-ideas] Re: Auto assignment of attributes

2022-04-21 Thread Josh Rosenberg
On Wed, Apr 20, 2022 at 3:31 PM Pablo Alcain wrote: > > About dataclasses, the point that Chris mentions, I think that they are in > a different scope from this, since they do much more stuff. But, beyond > this, a solution on the dataclass style would face a similar scenario: > since the `__init