[issue46190] Omit k in random.sample()

2021-12-28 Thread Raymond Hettinger
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

[issue46190] Omit k in random.sample()

2021-12-28 Thread Raymond Hettinger
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

[issue46190] Omit k in random.sample()

2021-12-28 Thread Raymond Hettinger
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

[issue46187] Optionally support rounding for math.isqrt()

2021-12-28 Thread Raymond Hettinger
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 (

[issue37295] Possible optimizations for math.comb()

2021-12-28 Thread Raymond Hettinger
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

[issue37295] Possible optimizations for math.comb()

2021-12-28 Thread Raymond Hettinger
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

[issue37295] Possible optimizations for math.comb()

2021-12-28 Thread Raymond Hettinger
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

[issue46187] Optionally support rounding for math.isqrt()

2021-12-27 Thread Raymond Hettinger
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

[issue9334] argparse does not accept options taking arguments beginning with dash (regression from optparse)

2021-12-26 Thread Raymond Hettinger
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

[issue9334] argparse does not accept options taking arguments beginning with dash (regression from optparse)

2021-12-26 Thread Raymond Hettinger
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

[issue46182] `super` and descriptor clarification

2021-12-26 Thread Raymond Hettinger
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

[issue46182] `super` and descriptor clarification

2021-12-26 Thread Raymond Hettinger
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. &

[issue37295] Possible optimizations for math.comb()

2021-12-23 Thread Raymond Hettinger
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

[issue46167] Parse assert (x == y, "Descriptive text") as statement params instead of a tuple

2021-12-23 Thread Raymond Hettinger
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

[issue46148] Optimize pathlib

2021-12-22 Thread Raymond Hettinger
Change by Raymond Hettinger : -- nosy: +pitrou ___ Python tracker <https://bugs.python.org/issue46148> ___ ___ Python-bugs-list mailing list Unsubscribe:

[issue37295] Possible optimizations for math.comb()

2021-12-21 Thread Raymond Hettinger
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

[issue37295] Possible optimizations for math.comb()

2021-12-21 Thread Raymond Hettinger
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

[issue37295] Possible optimizations for math.comb()

2021-12-20 Thread Raymond Hettinger
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

[issue37295] Possible optimizations for math.comb()

2021-12-20 Thread Raymond Hettinger
Change by Raymond Hettinger : -- Removed message: https://bugs.python.org/msg408963 ___ Python tracker <https://bugs.python.org/issue37295> ___ ___ Python-bug

[issue37295] Possible optimizations for math.comb()

2021-12-20 Thread Raymond Hettinger
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

[issue37295] Possible optimizations for math.comb()

2021-12-20 Thread Raymond Hettinger
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

[issue46132] Consider adding __slots__ to enums?

2021-12-19 Thread Raymond Hettinger
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

[issue46076] Document using __slots__ to provide per-attribute docstrings

2021-12-19 Thread Raymond Hettinger
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

[issue46076] Document using __slots__ to provide per-attribute docstrings

2021-12-19 Thread Raymond Hettinger
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

[issue46131] Add PyType_FastSubclass for float

2021-12-19 Thread Raymond Hettinger
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

[issue46131] Add PyType_FastSubclass for float

2021-12-19 Thread Raymond Hettinger
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

[issue46131] Add PyType_FastSubclass for float

2021-12-19 Thread Raymond Hettinger
Change by Raymond Hettinger : -- pull_requests: +28429 pull_request: https://github.com/python/cpython/pull/30208 ___ Python tracker <https://bugs.python.org/issue46

[issue46131] Add PyType_FastSubclass for float

2021-12-19 Thread Raymond Hettinger
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

[issue46131] Add PyType_FastSubclass for float

2021-12-19 Thread Raymond Hettinger
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

[issue46076] Document using __slots__ to provide per-attribute docstrings

2021-12-19 Thread Raymond Hettinger
Raymond Hettinger added the comment: Thanks for the PR. -- resolution: -> fixed stage: patch review -> resolved status: open -> closed ___ Python tracker <https://bugs.python.or

[issue46076] Document using __slots__ to provide per-attribute docstrings

2021-12-19 Thread Raymond Hettinger
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

[issue33567] Explicitly mention bytes and other buffers in the documentation for float()

2021-12-18 Thread Raymond Hettinger
Change by Raymond Hettinger : -- nosy: +rhettinger ___ Python tracker <https://bugs.python.org/issue33567> ___ ___ Python-bugs-list mailing list Unsubscribe:

[issue37295] Possible optimizations for math.comb()

2021-12-18 Thread Raymond Hettinger
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

[issue37295] Possible optimizations for math.comb()

2021-12-18 Thread Raymond Hettinger
Change by Raymond Hettinger : -- Removed message: https://bugs.python.org/msg408865 ___ Python tracker <https://bugs.python.org/issue37295> ___ ___ Python-bug

[issue37295] Possible optimizations for math.comb()

2021-12-18 Thread Raymond Hettinger
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

[issue46095] Improve SeqIter documentation

2021-12-17 Thread Raymond Hettinger
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

[issue46095] Warning about iterate/modify has unwarranted detail

2021-12-17 Thread Raymond Hettinger
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

[issue46092] Fix/update missing parameters in function signatures for Built-in Functions documentation.

2021-12-15 Thread Raymond Hettinger
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

[issue46081] Document the msg argument for assertRaises

2021-12-15 Thread Raymond Hettinger
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

[issue45959] Teach pprint about dict views

2021-12-15 Thread Raymond Hettinger
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

[issue46079] [doc] Broken URL in "Brief Tour of the Standard Library"

2021-12-15 Thread Raymond Hettinger
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

[issue46085] OrderedDict iterator allocates di_result unnecessarily

2021-12-15 Thread Raymond Hettinger
Change by Raymond Hettinger : -- nosy: +eric.snow ___ Python tracker <https://bugs.python.org/issue46085> ___ ___ Python-bugs-list mailing list Unsubscribe:

[issue46086] Add ratio_min() function to the difflib library

2021-12-15 Thread Raymond Hettinger
Change by Raymond Hettinger : -- assignee: -> tim.peters ___ Python tracker <https://bugs.python.org/issue46086> ___ ___ Python-bugs-list mailing list Un

[issue25864] collections.abc.Mapping should include a __reversed__ that raises TypeError

2021-12-14 Thread Raymond Hettinger
Change by Raymond Hettinger : -- status: pending -> closed ___ Python tracker <https://bugs.python.org/issue25864> ___ ___ Python-bugs-list mailing list Un

[issue46068] Change use of warnings.warn to logging.warning in a few places

2021-12-13 Thread Raymond Hettinger
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

[issue46068] Change use of warnings.warn to logging.warning in a few places

2021-12-13 Thread Raymond Hettinger
Change by Raymond Hettinger : -- Removed message: https://bugs.python.org/msg408512 ___ Python tracker <https://bugs.python.org/issue46068> ___ ___ Python-bug

[issue46068] Change use of warnings.warn to logging.warning in a few places

2021-12-13 Thread Raymond Hettinger
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

[issue46041] Add reference counting micro-optimizations to listobject.c

2021-12-10 Thread Raymond Hettinger
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

[issue32683] isinstance is calling ob.__getattribute__ as a fallback instead of object.__class__.__get__

2021-12-09 Thread Raymond Hettinger
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. -

[issue46020] Optimize long_pow for the common case

2021-12-09 Thread Raymond Hettinger
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

[issue46020] Optimize long_pow for the common case

2021-12-09 Thread Raymond Hettinger
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

[issue46020] Optimize long_pow for the common case

2021-12-08 Thread Raymond Hettinger
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

[issue14965] super() and property inheritance behavior

2021-12-08 Thread Raymond Hettinger
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

[issue14965] super() and property inheritance behavior

2021-12-08 Thread Raymond Hettinger
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

[issue39694] Incorrect dictionary unpacking when calling str.format

2021-12-08 Thread Raymond Hettinger
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

[issue46019] collections.Counter - Cast list of keys into set to remove iteration over duplicate elements for __le__, __ge__ and __eq__

2021-12-08 Thread Raymond Hettinger
Change by Raymond Hettinger : -- resolution: -> not a bug stage: patch review -> resolved status: open -> closed ___ Python tracker <https://bugs.python.or

[issue46019] collections.Counter - Cast list of keys into set to remove iteration over duplicate elements for __le__, __ge__ and __eq__

2021-12-08 Thread Raymond Hettinger
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

[issue46013] Confusing period in object.__hash__ doc

2021-12-08 Thread Raymond Hettinger
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

[issue31184] Fix data descriptor detection in inspect.getattr_static

2021-12-07 Thread Raymond Hettinger
Change by Raymond Hettinger : -- assignee: rhettinger -> ___ Python tracker <https://bugs.python.org/issue31184> ___ ___ Python-bugs-list mailing list Un

[issue20751] Harmonize descriptor protocol documentation: direct call, super binding with Descriptor Howto docs

2021-12-07 Thread Raymond Hettinger
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

[issue20751] Harmonize descriptor protocol documentation: direct call, super binding with Descriptor Howto docs

2021-12-07 Thread Raymond Hettinger
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

[issue20751] Harmonize descriptor protocol documentation: direct call, super binding with Descriptor Howto docs

2021-12-07 Thread Raymond Hettinger
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

[issue31184] Fix data descriptor detection in inspect.getattr_static

2021-12-07 Thread Raymond Hettinger
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

[issue44166] Make IndexError messages for list more informative

2021-12-05 Thread Raymond Hettinger
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

[issue44166] Make IndexError messages for list more informative

2021-12-05 Thread Raymond Hettinger
Change by Raymond Hettinger : -- assignee: -> rhettinger ___ Python tracker <https://bugs.python.org/issue44166> ___ ___ Python-bugs-list mailing list Un

[issue44166] Make IndexError messages for list more informative

2021-12-05 Thread Raymond Hettinger
Change by Raymond Hettinger : -- resolution: -> rejected stage: patch review -> resolved status: open -> closed ___ Python tracker <https://bugs.python.or

[issue44166] Make IndexError messages for list more informative

2021-12-05 Thread Raymond Hettinger
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

[issue44166] Make IndexError messages for list more informative

2021-12-05 Thread Raymond Hettinger
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

[issue45976] Random._randbelow() loses time by caching an attribute lookup

2021-12-04 Thread Raymond Hettinger
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

[issue45975] Simplify some while-loops with walrus operator

2021-12-04 Thread Raymond Hettinger
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

[issue45976] Random._randbelow() loses time by caching an attribute lookup

2021-12-03 Thread Raymond Hettinger
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

[issue45976] Random._randbelow() loses time by caching an attribute lookup

2021-12-03 Thread Raymond Hettinger
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

[issue45975] Simplify some while-loops with walrus operator

2021-12-03 Thread Raymond Hettinger
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

[issue45976] Random._randbelow() loses time by caching an attribute lookup

2021-12-03 Thread Raymond Hettinger
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

[issue20751] Harmonize descriptor protocol documentation: direct call, super binding with Descriptor Howto docs

2021-12-03 Thread Raymond Hettinger
Change by Raymond Hettinger : -- stage: patch review -> resolved status: open -> closed ___ Python tracker <https://bugs.python.org/issue20751> ___ ___ Pyth

[issue20751] Harmonize descriptor protocol documentation: direct call, super binding with Descriptor Howto docs

2021-12-03 Thread Raymond Hettinger
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

[issue45976] Random._randbelow() loses time by caching an attribute lookup

2021-12-03 Thread Raymond Hettinger
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

[issue23317] Incorrect description of descriptor invocation in Python Language Reference

2021-12-03 Thread Raymond Hettinger
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

[issue31735] Documentation incorrectly states how descriptors are invoked

2021-12-03 Thread Raymond Hettinger
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

[issue20751] Harmonize descriptor protocol documentation: direct call, super binding with Descriptor Howto docs

2021-12-03 Thread Raymond Hettinger
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

[issue20751] Harmonize descriptor protocol documentation: direct call, super binding with Descriptor Howto docs

2021-12-03 Thread Raymond Hettinger
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

[issue31441] Descriptor example in documentation is confusing, possibly wrong

2021-12-03 Thread Raymond Hettinger
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

[issue31735] Documentation incorrectly states how descriptors are invoked

2021-12-03 Thread Raymond Hettinger
Change by Raymond Hettinger : -- assignee: docs@python -> rhettinger ___ Python tracker <https://bugs.python.org/issue31735> ___ ___ Python-bugs-list mai

[issue20751] Harmonize descriptor protocol documentation: direct call, super binding with Descriptor Howto docs

2021-12-03 Thread Raymond Hettinger
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 <

[issue20751] Misleading descriptor protocol documentation: direct call, super binding

2021-12-03 Thread Raymond Hettinger
Change by Raymond Hettinger : -- assignee: docs@python -> rhettinger ___ Python tracker <https://bugs.python.org/issue20751> ___ ___ Python-bugs-list mai

[issue45959] Teach pprint about dict views

2021-12-01 Thread Raymond Hettinger
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

[issue45356] Calling `help` executes @classmethod @property decorated methods

2021-12-01 Thread Raymond Hettinger
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

[issue45956] Add scanf regular expressions to re

2021-12-01 Thread Raymond Hettinger
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

[issue27779] Sync-up docstrings in C version of the the decimal module

2021-11-30 Thread Raymond Hettinger
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__

[issue45876] Improve accuracy of stdev functions in statistics

2021-11-30 Thread Raymond Hettinger
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

[issue45876] Improve accuracy of stdev functions in statistics

2021-11-30 Thread Raymond Hettinger
Change by Raymond Hettinger : -- pull_requests: +28095 pull_request: https://github.com/python/cpython/pull/29869 ___ Python tracker <https://bugs.python.org/issue45

[issue45876] Improve accuracy of stdev functions in statistics

2021-11-30 Thread Raymond Hettinger
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

[issue45936] collections.Counter drops key if value is 0 and updating using += operator

2021-11-29 Thread Raymond Hettinger
Change by Raymond Hettinger : -- assignee: -> rhettinger ___ Python tracker <https://bugs.python.org/issue45936> ___ ___ Python-bugs-list mailing list Un

[issue45936] collections.Counter drops key if value is 0 and updating using += operator

2021-11-29 Thread Raymond Hettinger
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

[issue22656] `help` ignores `__doc__` of descriptors

2021-11-29 Thread Raymond Hettinger
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

[issue7951] Should str.format allow negative indexes when used for __getitem__ access?

2021-11-29 Thread Raymond Hettinger
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

[issue45451] IDLE Shell GUI - remove window border

2021-11-29 Thread Raymond Hettinger
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

[issue45876] Improve accuracy of stdev functions in statistics

2021-11-28 Thread Raymond Hettinger
Change by Raymond Hettinger : -- pull_requests: +28059 pull_request: https://github.com/python/cpython/pull/29828 ___ Python tracker <https://bugs.python.org/issue45

[issue45918] Possibly use ROUND_05UP in decimal's localcontext() example

2021-11-28 Thread Raymond Hettinger
Change by Raymond Hettinger : -- resolution: -> rejected stage: -> resolved status: open -> closed ___ Python tracker <https://bugs.python.or

[issue45918] Possibly use ROUND_05UP in decimal's localcontext() example

2021-11-28 Thread Raymond Hettinger
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

<    1   2   3   4   5   6   7   8   9   10   >