> 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
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 *
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,
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
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
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
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
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?
>
>
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
"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
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
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
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
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
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
15 matches
Mail list logo