Raymond Hettinger added the comment:
> My suggestion is not to set k=1 when omitted but to assign it a random value
Sorry, I think that is just bizarre. Also, some populations are *very* large,
so a minor user accident of omitting a parameter would result in a large
unexpected out
Raymond Hettinger added the comment:
Okay. Thank for the quick response and the suggestion. I'm going to mark this
one as closed. AFAICT, it distracts users from better solutions.
I did a quick code search for sample(). The k==1 case is rare and in most
cases the code should have used
Raymond Hettinger added the comment:
If all you want is a sample where k==1, then use choice(). That is clearer and
more efficient.
The sample() function is for sampling without replacement which only makes
sense when k > 1; otherwise, choice() or choices() is usually what you w
Raymond Hettinger added the comment:
> Sweet! New one on me
Tim already knows this but for the record the derivation is isn't tricky.
With y=isqrt(x), then next root is at y+1 and the half way point is y+1/2 which
isn't an integer. The corresponding squares are y**2, (y+1/2)**2, and
(
Raymond Hettinger added the comment:
Also, it would help Serhiy's divide and conquer algorithm if the fast cases
included the sides of Pascal's triangle rather than just the top:
if n < TableSize and k < limits[n]:
return comb_small(n, k)
return comb_slow(n, k)
Build the
Raymond Hettinger added the comment:
The shift table is an array of uint8_t, so it would be tiny (nearly fitting in
one cache line).
--
___
Python tracker
<https://bugs.python.org/issue37
Raymond Hettinger added the comment:
It's a little late, but I had a thought that code could be made more general,
slightly faster, and much easier to understand if the popcount logic were to be
replaced with a table that records how many bits of the factorial were shifted
out to make
New submission from Raymond Hettinger :
By default, isqrt(n) gives the floor of the exact square of n. It would be
nice to have a flag to give a rounded result:
y = isqrt(n, round=True)
Alternatively, set a mode argument to one of {'floor', 'round', 'ceil'}:
y = isqrt(n, mode
Raymond Hettinger added the comment:
> we should undo the deprecation of optparse in the documentation
> (https://bugs.python.org/issue37103), since the stated justification
> for that deprecation was that optparse will not be developed further.
While optparse that it isn't being
Raymond Hettinger added the comment:
> I believe that the behavior is so deeply ingrained in how argparse
> works that it can't be changed.
I think so as well. Handling arguments with a dash prefiew could be viewed as
fundamental design flaw except for the fact that the module has b
Raymond Hettinger added the comment:
I'm reluctant to give any more space to the least important case, one that
rarely arises in practice. The text in the PR is wordy and IMO creates more
confusion that it solves.
Per the dev-guide, we mostly avoid "preachy" text. No, "it
Raymond Hettinger added the comment:
> "a base class ``B`` following ``A``" shouldn't it be "the base
> class"? . After all, there is at most one base class following ``A``
No. There can be other classes in the chain. The first to match the lookup
wins.
&
Raymond Hettinger added the comment:
[Mark]
> Should I code up my suggestion in a PR,
Yes, go for it.
--
___
Python tracker
<https://bugs.python.org/issu
Raymond Hettinger added the comment:
> can we finally get rid of this language wart
Yes, please. This is a pretty bad pitfall.
I've seen this happen to people who've been conditioned by other languages to
think of assert() as a macro or function:
assert(sometest, somemess
Change by Raymond Hettinger :
--
nosy: +pitrou
___
Python tracker
<https://bugs.python.org/issue46148>
___
___
Python-bugs-list mailing list
Unsubscribe:
Raymond Hettinger added the comment:
Am I correct in my understanding the 64 bits are always available, that 128 bit
ints aren't universal, and that #ifdefs would be needed to extend the range of
the table for systems that support
Raymond Hettinger added the comment:
> Finv = [pow(fodd, -1, 2**64) for fodd in Fodd]
This is a good trick. I had already experimented with separating factorials
into an odd component and a shift count, but failed to get a speed-up because
the divisions were slow. Having a ta
Raymond Hettinger added the comment:
> Just curious about why the focus on the newer exp2 and log2?
No particular reason, those happened to give slighy best results on macOS.
Across compilers, plain exp() is likely the most mature.
The quality of log() is irrelevant because it isn't u
Change by Raymond Hettinger :
--
Removed message: https://bugs.python.org/msg408963
___
Python tracker
<https://bugs.python.org/issue37295>
___
___
Python-bug
Raymond Hettinger added the comment:
Stand by. I think I can implement this using only bit integer arithmetic. Will
post tomorrow.
--
___
Python tracker
<https://bugs.python.org/issue37
Raymond Hettinger added the comment:
> The problem here is that C gives no guarantees about accuracy of either log2
> or exp2
* The input table has hard-wired constants so there is no dependency on log2().
The inputs can be as exact as pi, tau, and e.
* The C library's exp2() fu
Raymond Hettinger added the comment:
> In which case: consider this a feature request to
> consider adding __slots__ ...
A few thoughts:
* Enumerations tend to be small, so a space savings likely isn't relevant.
* In Python 3.11, the speed advantage of slots is now much smaller.
* Th
Raymond Hettinger added the comment:
New changeset 8bfb11a791679a33024c9857e082afed0d71e0b4 by Miss Islington (bot)
in branch '3.9':
bpo-46076: Improve documentation for per-attribute docstrings with `__slots__`
(GH-30109) (GH-30207)
https://github.com/python/cpython/commit
Raymond Hettinger added the comment:
New changeset d7537ac8e3a3ef15d2c5f3fe90e998618b6a97b9 by Miss Islington (bot)
in branch '3.10':
bpo-46076: Improve documentation for per-attribute docstrings with `__slots__`
(GH-30109) (GH-30206)
https://github.com/python/cpython/commit
Raymond Hettinger added the comment:
That would not change that slot space is at a premium and that we prefer to use
that space for high payoff optimizations.
--
___
Python tracker
<https://bugs.python.org/issue46
Raymond Hettinger added the comment:
New changeset 29ea68bd1dcf30842c2ed908a6d815bc1d90f484 by Raymond Hettinger in
branch 'main':
Revert "bpo-46131: add fastpath for PyFloat_Check() (GH-30200)" (GH-30208)
https://github.com/python/cpython/commit/29ea68bd1dcf30842c2ed908a6d815
Change by Raymond Hettinger :
--
pull_requests: +28429
pull_request: https://github.com/python/cpython/pull/30208
___
Python tracker
<https://bugs.python.org/issue46
Raymond Hettinger added the comment:
New changeset 2ef06d412531d1163dbc72877c88aedf3ed82a25 by Matti Picus in branch
'main':
bpo-46131: add fastpath for PyFloat_Check() (#30200)
https://github.com/python/cpython/commit/2ef06d412531d1163dbc72877c88aedf3ed82a25
Raymond Hettinger added the comment:
Thanks for the suggestion, but I also concur with Serhiy.
--
nosy: +rhettinger
resolution: -> rejected
stage: patch review -> resolved
status: open -> closed
___
Python tracker
<https://bug
Raymond Hettinger added the comment:
Thanks for the PR.
--
resolution: -> fixed
stage: patch review -> resolved
status: open -> closed
___
Python tracker
<https://bugs.python.or
Raymond Hettinger added the comment:
New changeset aeb9ef4c7287fe367b6e9adcf1c5f994d5bc1a09 by Alex Waygood in
branch 'main':
bpo-46076: Improve documentation for per-attribute docstrings with `__slots__`
(GH-30109)
https://github.com/python/cpython/commit
Change by Raymond Hettinger :
--
nosy: +rhettinger
___
Python tracker
<https://bugs.python.org/issue33567>
___
___
Python-bugs-list mailing list
Unsubscribe:
Raymond Hettinger added the comment:
For the small cases (say n < 50), we can get faster code by using a small (3Kb)
table of factorial logarithms:
double lf[50] = [log2(factorial(n)) for n in range(50)];
Then comb() and perm() function can be computed quickly and in constant time
us
Change by Raymond Hettinger :
--
Removed message: https://bugs.python.org/msg408865
___
Python tracker
<https://bugs.python.org/issue37295>
___
___
Python-bug
Raymond Hettinger added the comment:
For the small cases (say n < 50), we can get faster code by using a small (3Kb)
table of factorial logarithms:
double lf[50] = [log2(factorial(n)) for n in range(50)];
Then comb() and perm() can be computed quickly and in constant time using the
Change by Raymond Hettinger :
--
title: Warning about iterate/modify has unwarranted detail -> Improve SeqIter
documentation
type: enhancement ->
versions: +Python 3.11
___
Python tracker
<https://bugs.python.org/i
Raymond Hettinger added the comment:
I think this note can be removed. The tutorial now has coverage of mutating
while iterating. That is the correct place for discussion of looping
techniques.
The part about the "internal counter" needs to be rewritten and moved to
stdtypes.r
Raymond Hettinger added the comment:
My understanding is that we're holding off on adding the slash notation to the
main docs. The reason is that they are mostly unintelligible to the average
user.
--
nosy: +rhettinger
___
Python tracker
<ht
Raymond Hettinger added the comment:
I concur with Eric that the current presentation is reasonable and better than
adding boilerplate to every entry. It suffices that the docs cover the *msg*
argument once and that each entry includes *msg* in its signature.
Elsewhere in the docs we
Raymond Hettinger added the comment:
More accurate to say that it aspires to print in a single line ONLY if the
content fits in the specified width. Otherwise, it prints vertically with
appropriate indentation. Indeed, that is the entire purpose of the module;
otherwise, we would just use
Raymond Hettinger added the comment:
This seems to be a temporary outage, expected to be restored in the first half
of 2022. Source: https://www.usno.navy.mil/USNO/time/master-clock
I'll look for an alternative time source that is currently online.
--
assignee: docs@python
Change by Raymond Hettinger :
--
nosy: +eric.snow
___
Python tracker
<https://bugs.python.org/issue46085>
___
___
Python-bugs-list mailing list
Unsubscribe:
Change by Raymond Hettinger :
--
assignee: -> tim.peters
___
Python tracker
<https://bugs.python.org/issue46086>
___
___
Python-bugs-list mailing list
Un
Change by Raymond Hettinger :
--
status: pending -> closed
___
Python tracker
<https://bugs.python.org/issue25864>
___
___
Python-bugs-list mailing list
Un
Raymond Hettinger added the comment:
> The downside of making this change is that it may break 3rd party unit tests.
I don’t see any upside. The modules in question have been stable for a good
while. There’s no benefit to changing them.
Also, there is no strong agreement that the stand
Change by Raymond Hettinger :
--
Removed message: https://bugs.python.org/msg408512
___
Python tracker
<https://bugs.python.org/issue46068>
___
___
Python-bug
Raymond Hettinger added the comment:
> The downside of making this change is that it may break 3rd party unit tests.
I don’t see any upside. The modules in question have been stable for a good
while. There’s no benefit to changing them.
Also, there is no strong agreement that the stand
Raymond Hettinger added the comment:
The OP self-closed the PR.
--
nosy: +rhettinger
resolution: -> rejected
stage: patch review -> resolved
status: open -> closed
___
Python tracker
<https://bugs.python.or
Raymond Hettinger added the comment:
> Changing the way isinstance works internally might prove
> beneficial for such tools.
ISTM you're advocating a design change rather than discussing a bug report.
The python-ideas mail list would be a better forum than the tracker.
-
Raymond Hettinger added the comment:
The situation for floats is also disappointing:
$ python3.11 -m timeit -s 'x=1.1' 'x ** 2'
500 loops, best of 5: 60.8 nsec per loop
$ python3.11 -m timeit -s 'x=1.1' 'x ** 2.0'
500 loops, best of 5: 51.5 nsec per loop
$ python3.11 -m timeit -s 'x
Raymond Hettinger added the comment:
Hmm, I had just looked at that code and it wasn't at all obvious that an
optimization had been added. I expected something like:
if (exp==2) return PyNumber_Multiply(x, x);
I wonder where the extra clock cycles are going. Looking at the ceval.c
New submission from Raymond Hettinger :
The expression 'x * x' is faster than 'x ** 2'.
In Python3.10, the speed difference was enormous. Due to ceval optimizations,
the difference in Python3.11 is tighter; however, there is still room for
improvement.
The code for long_pow() doesn't
Raymond Hettinger added the comment:
Another thought: Given that this tracker issue has been open for a decade
without resolution, we have evidence that this isn't an important problem in
practice.
Arguably, people have been better off being nudged in another direction toward
better
Raymond Hettinger added the comment:
-0 from me as well. I don't think this is common or something that should be
encouraged. As Andrew points out, "del super().x" doesn't have an obvious
meaning and it could be regarded as a code smell.
The OP's first example would be an unpl
Raymond Hettinger added the comment:
IMO, there is no actual problem being solved here. Instead there is just a
concern that something doesn't feel right. Given that there is no problem in
practice, I recommend closing this rather than cluttering docs, tests, or the C
code for a non
Change by Raymond Hettinger :
--
resolution: -> not a bug
stage: patch review -> resolved
status: open -> closed
___
Python tracker
<https://bugs.python.or
Raymond Hettinger added the comment:
> casting c to a set will remove duplicates and allow faster iteration
Sorry, but this doesn't make any sense. The *c* is either *self* or *other*,
both of which are instances of Counter which is itself a subclass of dict. So,
the input cannot h
Raymond Hettinger added the comment:
A line break would look weird. Let's add plain English instead.
- including set, frozenset, and dict. __hash__() should return an integer.
+ including set, frozenset, and dict. The __hash__() method should return an
integer.
--
nosy
Change by Raymond Hettinger :
--
assignee: rhettinger ->
___
Python tracker
<https://bugs.python.org/issue31184>
___
___
Python-bugs-list mailing list
Un
Raymond Hettinger added the comment:
> I guess here ``obj`` was supposed to be ``a``.
Okay, I updated the variable name to match the rest of the example.
> But is the description correct when it comes to what class is used where?
It looks fine to me. It is harmonious with the other
Raymond Hettinger added the comment:
New changeset 4b1cfc1f30327e76a2d845cc274be56b34b1 by Raymond Hettinger in
branch 'main':
bpo-20751: Match variable name to the example. (GH-29980)
https://github.com/python/cpython/commit/4b1cfc1f30327e76a2d845cc274be56b34b1
Change by Raymond Hettinger :
--
pull_requests: +28206
stage: resolved -> patch review
pull_request: https://github.com/python/cpython/pull/29980
___
Python tracker
<https://bugs.python.org/issu
Raymond Hettinger added the comment:
Can you give an example of where getattr_static() is not doing what you expect?
--
assignee: -> rhettinger
components: +Library (Lib)
nosy: +rhettinger
type: -> behavior
versions: -Python 3.10, Python 3.3, Python 3.4, Python 3.5, Pyth
Raymond Hettinger added the comment:
Thank for the suggestion. While we're going to a pass on this one, no doubt
there are other places that language can improve its communication with the
user. Please continue to submit ideas and patches
Change by Raymond Hettinger :
--
assignee: -> rhettinger
___
Python tracker
<https://bugs.python.org/issue44166>
___
___
Python-bugs-list mailing list
Un
Change by Raymond Hettinger :
--
resolution: -> rejected
stage: patch review -> resolved
status: open -> closed
___
Python tracker
<https://bugs.python.or
Raymond Hettinger added the comment:
Here's another way to think of it:
The call s[i] raising an IndexError isn't a numerical error, it is a conceptual
error. Knowing that i==15 and len(s)==10 doesn't usually help resolve the
problem. The fix typically isn't replacing s[i] with s[i - 5
Raymond Hettinger added the comment:
I also share Serhiy's concerns and prefer that it be left as-is.
Conceptually, adding more information in the error message would make it more
useful for debugging, but in practice, it would rarely be helpful. In teaching
and coaching Python, I've
Raymond Hettinger added the comment:
Notes
=
Without Boundmethod
---
LOAD FAST self
LOAD METHOD getrandbits
LOAD FAST k
CALL_METHOD 1
Form Boundmethod
LOAD FAST self
LOAD ATTR getrandbits
STORE FAST getrandbits
Call Boundmethod
Raymond Hettinger added the comment:
> As I mentioned in the PR, merging this can make future
> backports to 3.6 and 3.7 more complicated.
That's correct, but it is also true that we do very few of those and the
likelihood of a conflict with one of these edits
Raymond Hettinger added the comment:
On the current 3.11, I do get a speedup below a power of two, but a slight
degradation (as expected) at power of two.
python3.11 -m timeit -s 'from random import randrange' 'randrange(65535)'
python3.11 -m timeit -s 'from random import randrange
Raymond Hettinger added the comment:
I just did a few timings using the stock python.org Mac builds. Only Python
3.10 gave the expected speed-up. Python 3.8 and Python 3.9 got slower. Python
3.11 was slightly slower.
I think we should pass on this proposed change. The current code
Raymond Hettinger added the comment:
The general rule as stated by Zachary is correct; however, I'm in mildly favor
of this PR because these are the use cases that the walrus operator was
specifically designed for. That said, it would be nice to verify that timings
don't get worse
Raymond Hettinger added the comment:
* If you post a timing script, it will make it easier for me to verify this
across versions and across machine and for various input sizes.
* If you have time, do run some benchmarks for _randbelow_without_getrandbits()
* Try your change with and without
Change by Raymond Hettinger :
--
stage: patch review -> resolved
status: open -> closed
___
Python tracker
<https://bugs.python.org/issue20751>
___
___
Pyth
Raymond Hettinger added the comment:
New changeset 135ecc3492cee259090fd4aaed9056c130cd2eba by Raymond Hettinger in
branch 'main':
bpo-20751: Replace method example with attribute example, matching the
descriptor howto (GH-29909)
https://github.com/python/cpython/commit
Raymond Hettinger added the comment:
Thanks for the suggestion. I'll try this out on various builds and machines to
see how it works out. The speed of locals is consistently fast, but the speed
of method calls has varied over the last few versions of Python (generally
getting faster
Raymond Hettinger added the comment:
I think we can leave this as-is. It does a reasonable job of communicating
where the descriptor is found and the arguments used when it is called.
Marking this as out of date because later in the howto guide there is a precise
pure python equivalent
Raymond Hettinger added the comment:
> it should have
>
> d.__get__(obj, type(obj)) instead of d.__get__(obj)
The objtype argument is optional as shown in all of the examples. The call
from object.__getattribute__() always passes in both parameters, even though
only the first is
Change by Raymond Hettinger :
--
keywords: +patch
pull_requests: +28134
stage: needs patch -> patch review
pull_request: https://github.com/python/cpython/pull/29909
___
Python tracker
<https://bugs.python.org/issu
Raymond Hettinger added the comment:
Regarding comment #1, The wording is correct and there was a reason for using a
method. While super() can be used for attribute lookup, use cases are almost
entirely dominated by method lookups. For many users, an attribute lookup with
super
Raymond Hettinger added the comment:
This example was removed and replaced with better examples.
--
resolution: -> out of date
stage: -> resolved
status: open -> closed
___
Python tracker
<https://bugs.python.or
Change by Raymond Hettinger :
--
assignee: docs@python -> rhettinger
___
Python tracker
<https://bugs.python.org/issue31735>
___
___
Python-bugs-list mai
Change by Raymond Hettinger :
--
title: Misleading descriptor protocol documentation: direct call, super binding
-> Harmonize descriptor protocol documentation: direct call, super binding with
Descriptor Howto docs
___
Python tracker
<
Change by Raymond Hettinger :
--
assignee: docs@python -> rhettinger
___
Python tracker
<https://bugs.python.org/issue20751>
___
___
Python-bugs-list mai
New submission from Raymond Hettinger :
The pprint() code has a number of type or protocol specific handlers but
doesn't have one for dict views. So, we don't get pretty printing for the
key(), values(), and items():
d = {i:i for i in range(100)}
pprint(d) # This is handled
Raymond Hettinger added the comment:
In Python 3.10, classmethod() added a __wrapped__ attribute. Presumably, any
use case for implicit chaining can now be accomplished in an explicit and
controlled manner.
--
___
Python tracker
<ht
Raymond Hettinger added the comment:
The scanf() translation table primarily serves as a way to learn regex syntax
for people who only know scanf syntax.
It would defeat the educational purpose to immortalize the translation as fixed
constants. For the most part, people are better off
Raymond Hettinger added the comment:
One way to do is to dynamically update the docstrings on import. Something
like this:
for name in dir(_decimal.Decimal):
if name.startswith('_'):
continue
py_method = getattr(_decimal.Decimal, name)
py_doc = py_method.__doc__
Raymond Hettinger added the comment:
New changeset 0aa0bd056349f73de9577ccc38560c1d01864d51 by Raymond Hettinger in
branch 'main':
bpo-45876: Have stdev() also use decimal specific square root. (GH-29869)
https://github.com/python/cpython/commit/0aa0bd056349f73de9577ccc38560c1d01864d51
Change by Raymond Hettinger :
--
pull_requests: +28095
pull_request: https://github.com/python/cpython/pull/29869
___
Python tracker
<https://bugs.python.org/issue45
Raymond Hettinger added the comment:
New changeset a39f46afdead515e7ac3722464b5ee8d7b0b2c9b by Raymond Hettinger in
branch 'main':
bpo-45876: Correctly rounded stdev() and pstdev() for the Decimal case
(GH-29828)
https://github.com/python/cpython/commit
Change by Raymond Hettinger :
--
assignee: -> rhettinger
___
Python tracker
<https://bugs.python.org/issue45936>
___
___
Python-bugs-list mailing list
Un
Raymond Hettinger added the comment:
I don't think there is a need to list the inplace methods. They were put in to
optimize what was already occurring when only the __add__ method was defined.
Also, other container typically don't specifically call out the inplace methods
Raymond Hettinger added the comment:
This was fixed long ago in commit ac4bdcc80e986bdd5b9d10ab0bce35aabb790a3e
The code is in inspect.py::_finddoc(). See issue 25503.
--
nosy: +rhettinger
resolution: -> out of date
stage: patch review -> resolved
status: open -&g
Raymond Hettinger added the comment:
I recommend not adding support for negative indexing to format() for accessing
positional arguments. There is almost no reason to do this because it almost
always makes the format string less readable, because the number of arguments
is always known
Raymond Hettinger added the comment:
I request that this entire new feature be reverted. Having used it in
classroom environment, it has been a catastrophe for teaching and is a
significant regression in usability.
Here are my notes so far:
1) As the OP says, this strong vertical line
Change by Raymond Hettinger :
--
pull_requests: +28059
pull_request: https://github.com/python/cpython/pull/29828
___
Python tracker
<https://bugs.python.org/issue45
Change by Raymond Hettinger :
--
resolution: -> rejected
stage: -> resolved
status: open -> closed
___
Python tracker
<https://bugs.python.or
Raymond Hettinger added the comment:
I’m concerned though that the intermediate calculations might be worse off than
with some other rounding mode.
--
___
Python tracker
<https://bugs.python.org/issue45
201 - 300 of 9507 matches
Mail list logo