[issue45024] Cannot extend collections ABCs with protocol

2021-09-07 Thread Raymond Hettinger
Change by Raymond Hettinger : -- keywords: +patch pull_requests: +26643 stage: -> patch review pull_request: https://github.com/python/cpython/pull/28218 ___ Python tracker <https://bugs.python.org/issu

[issue45104] Error in __new__ docs

2021-09-07 Thread Raymond Hettinger
Change by Raymond Hettinger : -- keywords: +patch pull_requests: +26635 stage: -> patch review pull_request: https://github.com/python/cpython/pull/28210 ___ Python tracker <https://bugs.python.org/issu

[issue38644] Pass explicitly tstate to function calls

2021-09-06 Thread Raymond Hettinger
Raymond Hettinger added the comment: This adds cost to our most critical code paths. For example, type_call() will now be slower for every single object instantiation. -- nosy: +rhettinger ___ Python tracker <https://bugs.python.org/issue38

[issue45104] Error in __new__ docs

2021-09-06 Thread Raymond Hettinger
Raymond Hettinger added the comment: I would be happy with just "instance of cls". Elsewhere in the docs, that phrasing almost always means "instance of a cls or instance of a subclass of cls". Also, it is consistent with the meaning of isinstance(inst, cls) unless ove

[issue7391] [doc] restore the "Idioms and Anti-Idioms in Python" document

2021-09-06 Thread Raymond Hettinger
Raymond Hettinger added the comment: The document out of date when it was removed and is now another dozen years older. Since then no one has expresses any interest with this and other tools have emerged to deal with code formatting. -- resolution: -> out of date st

[issue45116] Performance regression 3.10b1 and later on Windows

2021-09-06 Thread Raymond Hettinger
Raymond Hettinger added the comment: Perhaps these critical code sections should have been left as macros. It is difficult to assuring system wide inlining across modules. -- nosy: +rhettinger ___ Python tracker <https://bugs.python.

[issue45112] Python exception object is different after pickle.dumps and pickle.loads

2021-09-06 Thread Raymond Hettinger
Raymond Hettinger added the comment: It would be nice if exception pickling was more friendly to subclasses. Perhaps, the default should be to store and restore all state including args and a __dict__ if any. -- ___ Python tracker <ht

[issue45112] Python exception object is different after pickle.dumps and pickle.loads

2021-09-06 Thread Raymond Hettinger
Change by Raymond Hettinger : -- resolution: not a bug -> status: closed -> open ___ Python tracker <https://bugs.python.org/issue45112> ___ ___ Pyth

[issue45112] Python exception object is different after pickle.dumps and pickle.loads

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

[issue45112] Python exception object is different after pickle.dumps and pickle.loads

2021-09-06 Thread Raymond Hettinger
Raymond Hettinger added the comment: Pickling customized subclasses can be tricky. The essential details are here: https://docs.python.org/3/library/pickle.html#object.__reduce__ Here's some code to get you started. class ExcA(Exception): def __init__(self, want):

[issue45110] argparse repeats itself when formatting help metavars

2021-09-05 Thread Raymond Hettinger
Raymond Hettinger added the comment: I don't agree this should be changed. The repetition helps improve understanding because not everyone would assume that a METAVAR shown once would automatically also apply to its long form. Also, showing the METAVAR more than one is a norm.

[issue45100] Improve help() by making typing.overload() information accessible at runtime

2021-09-05 Thread Raymond Hettinger
Raymond Hettinger added the comment: Note, I'm not proposing a create_function() decorator. That is just for the proof of concept. The actual logic would go into normal function creation, the same place that __annotations__ gets added. Also, there may be a better place than

[issue45100] Improve help() by making typing.overload() information accessible at runtime

2021-09-05 Thread Raymond Hettinger
Change by Raymond Hettinger : -- title: Teach help about typing.overload() -> Improve help() by making typing.overload() information accessible at runtime versions: +Python 3.11 ___ Python tracker <https://bugs.python.org/issu

[issue45100] Teach help about typing.overload()

2021-09-05 Thread Raymond Hettinger
Raymond Hettinger added the comment: > The two @overload definitions will be overwritten by > the non-overload one at runtime, and hence will ever > been seen by help(). We can fix this by adding an __overloads__ attribute. The overload decorator can accumulate the chain in an

[issue44571] itertools: takedowhile()

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

[issue44571] itertools: takedowhile()

2021-09-04 Thread Raymond Hettinger
Raymond Hettinger added the comment: New changeset 91be41ad933e24bff26353a19f56447e17fb6367 by Raymond Hettinger in branch 'main': bpo-44571: Add itertool recipe for a variant of takewhile() (GH-28167) https://github.com/python/cpython/commit/91be41ad933e24bff26353a19f5644

[issue44571] itertools: takedowhile()

2021-09-04 Thread Raymond Hettinger
Change by Raymond Hettinger : -- keywords: +patch pull_requests: +26596 stage: -> patch review pull_request: https://github.com/python/cpython/pull/28167 ___ Python tracker <https://bugs.python.org/issu

[issue45100] Teach help about typing.overload()

2021-09-04 Thread Raymond Hettinger
New submission from Raymond Hettinger : Python's help() function does not display overloaded function signatures. For example, this code: from typing import Union class Smudge(str): @overload def __getitem__(self, index: int) -

[issue45093] Add method to compare dicts accounting for order

2021-09-03 Thread Raymond Hettinger
Change by Raymond Hettinger : -- Removed message: https://bugs.python.org/msg401022 ___ Python tracker <https://bugs.python.org/issue45093> ___ ___ Python-bug

[issue45093] Add method to compare dicts accounting for order

2021-09-03 Thread Raymond Hettinger
Raymond Hettinger added the comment: -1 The dict API is too important to be burdened with a mostly useless and rarely needed method. Besides we already have simple ways to do it, for example: assert list(d.items()) == list(e.items()) or: assert OrderedDict(d) == OrderedDict(e

[issue45093] Add method to compare dicts accounting for order

2021-09-03 Thread Raymond Hettinger
Raymond Hettinger added the comment: -1 The dict API is to important to be burdened with a mostly useless and rarely needed method. Besides we already have simple ways to do it, for example: assert list(d.items()) == list(e.items()) or: assert OrderedDict(d) == OrderedDict(e

[issue44748] argparse: a bool indicating if arg was encountered

2021-09-02 Thread Raymond Hettinger
Raymond Hettinger added the comment: > I want the order of priority to fall back to the defaults, > if no value is specified in the config file. And if an argument > is passed via argv, then that value should take precedence > over what is set in the config file. from collec

[issue44748] argparse: a bool indicating if arg was encountered

2021-09-02 Thread Raymond Hettinger
Raymond Hettinger added the comment: > then you can't show the defaults in the help message. 1) The --help option doesn't normally show defaults. 2) Why would you show defaults in help, if you're going to ignore them in favor the values in config whenever they aren't

[issue44748] argparse: a bool indicating if arg was encountered

2021-09-02 Thread Raymond Hettinger
Raymond Hettinger added the comment: > With a config file loaded as part of the program, > overwrite the values loaded from the config file > if the argument was encountered in the argument vector. It seems to me that default values can already be used for this purpose: from

[issue45024] Cannot extend collections ABCs with protocol

2021-09-02 Thread Raymond Hettinger
Raymond Hettinger added the comment: The docs need to clarify which ABCs can satisfy isinstance() based solely on hasattr() logic and which ABCs require registration or direct subclassing. The docs should also explain why the more complex ABCs can't reliably be recognized based o

[issue45064] Raising AttributeError in descriptor decorator causing searching attribute in __mro__

2021-08-31 Thread Raymond Hettinger
Raymond Hettinger added the comment: To get a better insight into what is going on, see https://docs.python.org/3/howto/descriptor.html#invocation-from-an-instance The relevant text is, "So if __getattr__() exists, it is called whenever __getattribute__() raises AttributeError (e

[issue39218] Assertion failure when calling statistics.variance() on a float32 Numpy array

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

[issue39218] Assertion failure when calling statistics.variance() on a float32 Numpy array

2021-08-30 Thread Raymond Hettinger
Raymond Hettinger added the comment: New changeset 793f55bde9b0299100c12ddb0e6949c6eb4d85e5 by Raymond Hettinger in branch 'main': bpo-39218: Improve accuracy of variance calculation (GH-27960) https://github.com/python/cpython/commit/793f55bde9b0299100c12ddb0e6949

[issue45054] json module should issue warning about duplicate keys

2021-08-30 Thread Raymond Hettinger
Change by Raymond Hettinger : -- nosy: +bob.ippolito ___ Python tracker <https://bugs.python.org/issue45054> ___ ___ Python-bugs-list mailing list Unsubscribe:

[issue17576] PyNumber_Index() is not int-subclass friendly (or operator.index() docs lie)

2021-08-30 Thread Raymond Hettinger
Raymond Hettinger added the comment: > So I really *do* want to see the ability of __float__ > to return a non-float eventually removed. Note, the __str__ method on strings does not require an exact str. class S: def __str__(self): return self print(type

[issue45021] Race condition in thread.py

2021-08-29 Thread Raymond Hettinger
Change by Raymond Hettinger : -- nosy: +davin ___ Python tracker <https://bugs.python.org/issue45021> ___ ___ Python-bugs-list mailing list Unsubscribe:

[issue45044] Agreeing on error raised by large repeat value for sequences

2021-08-29 Thread Raymond Hettinger
Raymond Hettinger added the comment: These should be left as they are because they indicate different problems and solutions. The Overflow errors are dependent on PY_SSIZE_T_MAX. They indicate the that size is to big to store in a variable. Changing from a 32-bit build to a 64-bit build

[issue39218] Assertion failure when calling statistics.variance() on a float32 Numpy array

2021-08-26 Thread Raymond Hettinger
Raymond Hettinger added the comment: > what it's correcting for is an inaccurate value of "c" [...] I'll leave the logic as-is and just add a note about what is being corrected. > Numerically, it's probably not helpful. To make a difference, the mean wo

[issue39218] Assertion failure when calling statistics.variance() on a float32 Numpy array

2021-08-25 Thread Raymond Hettinger
Change by Raymond Hettinger : -- keywords: +patch pull_requests: +26406 stage: -> patch review pull_request: https://github.com/python/cpython/pull/27960 ___ Python tracker <https://bugs.python.org/issu

[issue39218] Assertion failure when calling statistics.variance() on a float32 Numpy array

2021-08-25 Thread Raymond Hettinger
Raymond Hettinger added the comment: The rounding correction in _ss() looks mathematically incorrect to me: ∑ (xᵢ - x̅ + εᵢ)² = ∑ (xᵢ - x̅)² - (∑ εᵢ)² ÷ n If we drop this logic (which seems completely bogus), all the tests still pass and the code becomes cleaner: def _ss(data, c=None

[issue45003] Documentation wrote __div__ instead of __truediv__

2021-08-25 Thread Raymond Hettinger
Raymond Hettinger added the comment: Would you like to submit a PR? -- nosy: +rhettinger ___ Python tracker <https://bugs.python.org/issue45003> ___ ___ Pytho

[issue37596] Reproducible pyc: frozenset is not serialized in a deterministic order

2021-08-25 Thread Raymond Hettinger
Raymond Hettinger added the comment: Looking again, I think code is correct as-is (am not sure about the depth adjustment though). Stylistically, it is different from the other blocks w_complex_object() that always have a "return" after setting p->error. The new code jumps to

[issue37596] Reproducible pyc: frozenset is not serialized in a deterministic order

2021-08-25 Thread Raymond Hettinger
Raymond Hettinger added the comment: Should the error paths decref the key and return NULL as they do elsewhere in the function? -- status: closed -> open ___ Python tracker <https://bugs.python.org/issu

[issue44986] Date formats in help messages of argparse

2021-08-24 Thread Raymond Hettinger
Change by Raymond Hettinger : -- Removed message: https://bugs.python.org/msg400243 ___ Python tracker <https://bugs.python.org/issue44986> ___ ___ Python-bug

[issue44986] Date formats in help messages of argparse

2021-08-24 Thread Raymond Hettinger
Raymond Hettinger added the comment: I don't think anything like this should be done. Besides breaking existing '%%' markup, it invents a new %-formatting notation. -- nosy: +rhettinger type: crash -> enhancement ___ Pyth

[issue44992] functools.lru_cache does not consider strings and numpy strings as equivalent

2021-08-24 Thread Raymond Hettinger
Raymond Hettinger added the comment: Thanks for the report but this is an allowed behavior and not a bug. Per the docs¹: If typed is set to true, function arguments of different types will be cached separately. For example, f(3) and f(3.0) will always be treated as distinct calls with

[issue37596] Reproducible pyc: frozenset is not serialized in a deterministic order

2021-08-23 Thread Raymond Hettinger
Change by Raymond Hettinger : -- Removed message: https://bugs.python.org/msg400182 ___ Python tracker <https://bugs.python.org/issue37596> ___ ___ Python-bug

[issue37596] Reproducible pyc: frozenset is not serialized in a deterministic order

2021-08-23 Thread Raymond Hettinger
Raymond Hettinger added the comment: Here's pure python code for experimentation: from marshal import dumps, loads def marshal_set(s): return dumps(sorted(s, key=dumps)) def unmarshal_set(m): return frozenset(loads(m)) def test(s): a

[issue37596] Reproducible pyc: frozenset is not serialized in a deterministic order

2021-08-23 Thread Raymond Hettinger
Raymond Hettinger added the comment: Here's pure python code for expirmentation: from marshal import dumps, loads def marshal_set(s): return dumps(sorted((dumps(value), value) for value in s)) def unmarshal_set(m): return {value for dump, value in lo

[issue37596] Reproducible pyc: frozenset is not serialized in a deterministic order

2021-08-23 Thread Raymond Hettinger
Raymond Hettinger added the comment: > I can clean it up and convert it to a PR if we decide > we want to go this route. +1 This is by far the smallest intervention that has been discussed. -- ___ Python tracker <https://bugs.p

[issue4442] document immutable type subclassing via __new__

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

[issue44973] @classmethod can be stacked on @property, but @staticmethod cannot

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

[issue44977] Deprecate delegation of int to __trunc__?

2021-08-22 Thread Raymond Hettinger
Raymond Hettinger added the comment: I retract the suggestion to deprecate __trunc__. -- ___ Python tracker <https://bugs.python.org/issue44977> ___ ___ Pytho

[issue44973] @classmethod can be stacked on @property, but @staticmethod cannot

2021-08-22 Thread Raymond Hettinger
Raymond Hettinger added the comment: The classmethod and staticmethod decorators have somewhat different semantics. Accessing a classmethod with C.cm creates a bound method object which has both __call__ and __get__. In contrast, accessing a staticmethod with C.sm returns the underlying

[issue44977] Deprecate delegation of int to __trunc__?

2021-08-22 Thread Raymond Hettinger
Raymond Hettinger added the comment: Possibly, we could have math.trunc() call __int__, letting us deprecate __trunc__. That would let users avoid gratuitous aliasing such as that in _pydecimal.py: __trunc__ = __int__ -- ___ Python tracker

[issue44977] Deprecate delegation of int to __trunc__?

2021-08-22 Thread Raymond Hettinger
Raymond Hettinger added the comment: Afterwards, do __trunc__ and math.trunc() still need to exist? They were mostly unused. Now they would also be unnecessary. Just having them around would be a point of confusion. -- nosy: +rhettinger

[issue44966] example code does not macth the very version(3.9)

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

[issue44966] example code does not macth the very version(3.9)

2021-08-21 Thread Raymond Hettinger
Raymond Hettinger added the comment: New changeset 407b3e0bb028c30fbf5efcf58c70c50eaa6712b0 by Miss Islington (bot) in branch '3.9': bpo-44966: Fix out-of-date traceback message (GH-27867) (GH-27876) https://github.com/python/cpython/commit/407b3e0bb028c30fbf5efcf58c70c5

[issue44966] example code does not macth the very version(3.9)

2021-08-21 Thread Raymond Hettinger
Raymond Hettinger added the comment: New changeset 15a64d89a31b7e91f0361c305b7b27d8761db93d by Raymond Hettinger in branch 'main': bpo-44966: Fix out-of-date traceback message (GH-27867) https://github.com/python/cpython/commit/15a64d89a31b7e91f0361c305b7b27

[issue21184] statistics.pvariance with known mean does not work as expected

2021-08-20 Thread Raymond Hettinger
Raymond Hettinger added the comment: See commit d71ab4f73887a6e2b380ddbbfe35b600d236fd4a for bpo-40855. -- nosy: +rhettinger resolution: -> fixed stage: needs patch -> resolved status: open -> closed ___ Python tracker <https://bug

[issue44966] example code does not macth the very version(3.9)

2021-08-20 Thread Raymond Hettinger
Change by Raymond Hettinger : -- keywords: +patch nosy: +rhettinger nosy_count: 2.0 -> 3.0 pull_requests: +26322 stage: -> patch review pull_request: https://github.com/python/cpython/pull/27867 ___ Python tracker <https://bugs.p

[issue39218] Assertion failure when calling statistics.variance() on a float32 Numpy array

2021-08-20 Thread Raymond Hettinger
Raymond Hettinger added the comment: Removing the assertion and implementing Steven's idea seems like the best way to go: sum((y:=(x-c)) * y for x in data) -- ___ Python tracker <https://bugs.python.org/is

[issue44943] Integrate PyHyphen into the textwrap module?

2021-08-20 Thread Raymond Hettinger
Raymond Hettinger added the comment: I concur with Terry. The suggestion is nice but it belongs outside the standard library. -- nosy: +rhettinger resolution: -> rejected stage: -> resolved status: open -> closed ___ Python tracke

[issue4442] document immutable type subclassing via __new__

2021-08-20 Thread Raymond Hettinger
Change by Raymond Hettinger : -- keywords: +patch nosy: +rhettinger nosy_count: 8.0 -> 9.0 pull_requests: +26321 stage: needs patch -> patch review pull_request: https://github.com/python/cpython/pull/27866 ___ Python tracker

[issue30999] statistics module: add a general selection function

2021-08-20 Thread Raymond Hettinger
Raymond Hettinger added the comment: No one has shown any interest in this in a long time. Marking is as closed for now. This issue can be reopened if there is an interest and a reasonable use case that can't be reasonably handled with sorted, min, or max. -- resol

[issue33084] statistics module: NaN handling in median, median_high an median_low

2021-08-20 Thread Raymond Hettinger
Raymond Hettinger added the comment: [Steven] > Thoughts? 1) Document that results are undefined if a NaN is present in the data. 2) Add function to strip NaNs from the data: def remove_nans(iterable): "Remove float('NaN') and other objects not e

[issue44944] Addition of _heappush_max method to complete the max heap implementation in Python's heapq module

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

[issue44931] Add "bidimap" to collections library: a simple bidirectional map

2021-08-17 Thread Raymond Hettinger
Raymond Hettinger added the comment: This has come up several times in the past and never moved forward. Part of the reason is that the mapping API doesn't translate cleanly to bidirectional lookups and it leaves users trapped if two keys every end up needing to be mapped to the same

[issue44845] Allow keyword arguments in code.__new__

2021-08-11 Thread Raymond Hettinger
Raymond Hettinger added the comment: Generally, construction time is faster if the arguments are positional only. Also, this isn't a method that people typically call directly — it is only quasi-public because the layout of the codestring is implementation dependent and changes ever

[issue41645] Typo First Page of Documentation

2021-08-08 Thread Raymond Hettinger
Raymond Hettinger added the comment: To my ears, the sentence reads nicely. I vote for leaving it as is. -- nosy: +rhettinger ___ Python tracker <https://bugs.python.org/issue41

[issue44867] types.MappingProxyType and collections.defaultdict

2021-08-08 Thread Raymond Hettinger
Raymond Hettinger added the comment: > `types.MappingProxyType` is documented as > 'Read-only proxy of a mapping'. But if used with a > `collections.defaultdict` mapping, it can modify > the underlying mapping. Technically, the underlying mapping is modifying it

[issue44605] functools.total_ordering doesn't work with metaclasses

2021-08-06 Thread Raymond Hettinger
Change by Raymond Hettinger : -- resolution: -> fixed stage: patch review -> resolved status: open -> closed versions: +Python 3.10, Python 3.9 ___ Python tracker <https://bugs.python.or

[issue44605] functools.total_ordering doesn't work with metaclasses

2021-08-06 Thread Raymond Hettinger
Raymond Hettinger added the comment: New changeset 66dd1a0e645f26b074547dccc92448169cb32410 by Miss Islington (bot) in branch '3.10': bpo-44605: Teach @total_ordering() to work with metaclasses (GH-27633) (GH-27640) https://github.com/python/cpyt

[issue44605] functools.total_ordering doesn't work with metaclasses

2021-08-06 Thread Raymond Hettinger
Raymond Hettinger added the comment: New changeset fde84170d06f74afd6f95d5b18cf3f733018191a by Miss Islington (bot) in branch '3.9': bpo-44605: Teach @total_ordering() to work with metaclasses (GH-27633) (GH-27641) https://github.com/python/cpyt

[issue44605] functools.total_ordering doesn't work with metaclasses

2021-08-06 Thread Raymond Hettinger
Raymond Hettinger added the comment: New changeset 1f7d64608b5c7f4c3d96b01b33e18ebf9dec8490 by Raymond Hettinger in branch 'main': bpo-44605: Teach @total_ordering() to work with metaclasses (GH-27633) https://github.com/python/cpython/commit/1f7d64608b5c7f4c3d96b01b33e18e

[issue44831] Inconsistency between datetime.now() and datetime.fromtimestamp(time.time(), None)

2021-08-06 Thread Raymond Hettinger
Change by Raymond Hettinger : -- nosy: +larry ___ Python tracker <https://bugs.python.org/issue44831> ___ ___ Python-bugs-list mailing list Unsubscribe:

[issue44831] Inconsistency between datetime.now() and datetime.fromtimestamp(time.time(), None)

2021-08-06 Thread Raymond Hettinger
Raymond Hettinger added the comment: The cause of the problem is inconsistent rounding modes: end = datetime.datetime.now() # always rounds down start = datetime.datetime.fromtimestamp(start, None) # sometimes rounds_up >From the C code in Modu

[issue44605] functools.total_ordering doesn't work with metaclasses

2021-08-06 Thread Raymond Hettinger
Change by Raymond Hettinger : -- keywords: +patch pull_requests: +26127 stage: needs patch -> patch review pull_request: https://github.com/python/cpython/pull/27633 ___ Python tracker <https://bugs.python.org/issu

[issue44605] functools.total_ordering doesn't work with metaclasses

2021-08-05 Thread Raymond Hettinger
Raymond Hettinger added the comment: > If the preference is to not support this use-case ,,, I don't really have a preference. Was just letting you know the pros and cons. I'll put together a PR with the "type(self).__lt__(self, other)" substitutions. Let me know

[issue44605] functools.total_ordering doesn't work with metaclasses

2021-08-05 Thread Raymond Hettinger
Raymond Hettinger added the comment: [Glyph] > why not decide on implementation at decoration time? We could do that and not incur performance issues. However, it would expand the API and double the size of the code. We've had no other reports about this issue since total_orderi

[issue41946] Add concrete examples to os.path documentation

2021-08-05 Thread Raymond Hettinger
Raymond Hettinger added the comment: If some examples are added, the should note which operating system is being used. -- ___ Python tracker <https://bugs.python.org/issue41

[issue41946] Add concrete examples to os.path documentation

2021-08-05 Thread Raymond Hettinger
Raymond Hettinger added the comment: Concrete examples for os.path are problematic because typical inputs and outputs vary across difference file systems. The point of os.path is to hide these differences. -- nosy: +rhettinger ___ Python tracker

[issue44605] functools.total_ordering doesn't work with metaclasses

2021-08-05 Thread Raymond Hettinger
Raymond Hettinger added the comment: Do you all have preference for 1) expanding the range of use cases to cover metaclasses but incurring a performance hit for common cases, or 2) leaving it as-is and documenting that it doesn't work for metacl

[issue43838] There is a way to access an underlying mapping in MappingProxyType

2021-08-05 Thread Raymond Hettinger
Raymond Hettinger added the comment: [Serhiy] > In particularly it allows to modify __dict__ of builtin types. This doesn't look like something that would happen accidentally. We've never had any bug reports about this occurring in the wild. [GvR] > Maybe we should n

[issue43468] functools.cached_property incorrectly locks the entire descriptor on class instead of per-instance locking

2021-08-04 Thread Raymond Hettinger
Change by Raymond Hettinger : -- keywords: +patch pull_requests: +26104 stage: -> patch review pull_request: https://github.com/python/cpython/pull/27609 ___ Python tracker <https://bugs.python.org/issu

[issue43468] functools.cached_property incorrectly locks the entire descriptor on class instead of per-instance locking

2021-08-03 Thread Raymond Hettinger
Raymond Hettinger added the comment: Here's the latest effort: --- def __get__(self, instance, owner=None): if instance is None: return self if self.attrname is None: raise Type

[issue44772] Regression in memory use of instances due to dictionary ordering

2021-08-03 Thread Raymond Hettinger
Raymond Hettinger added the comment: ISTM this was mostly a net win. We get compactness and sharing most of the time, and lose sharing only in cases like this where different instances of the same class happen to have different attributes. Personally, I would not have expected sharing to

[issue44782] LRU class given as example in OrderedDict docs not work on pop

2021-08-02 Thread Raymond Hettinger
Raymond Hettinger added the comment: New changeset c50a672eebb16cf778d9a3b22b72d506c3f54ced by Miss Islington (bot) in branch '3.9': bpo-44782: Improve OrderedDict recipe for LRU cache variants (GH-27536) (GH-27567) https://github.com/python/cpyt

[issue44782] LRU class given as example in OrderedDict docs not work on pop

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

[issue44782] LRU class given as example in OrderedDict docs not work on pop

2021-08-02 Thread Raymond Hettinger
Raymond Hettinger added the comment: New changeset 54f185b6d321a6354aef2b2886c766677f487ecb by Raymond Hettinger in branch 'main': bpo-44782: Improve OrderedDict recipe for LRU cache variants (GH-27536) https://github.com/python/cpython/commit/54f185b6d321a6354aef2b2886c766

[issue44782] LRU class given as example in OrderedDict docs not work on pop

2021-08-01 Thread Raymond Hettinger
Raymond Hettinger added the comment: > But if you need lru_cache() why not use lru_cache() > from the stdlib? This gives a foundation for people who want to roll their own variants of the standard library lru_cache(). From here, people can experiment with pickle support, dynamic re

[issue44782] LRU class given as example in OrderedDict docs not work on pop

2021-08-01 Thread Raymond Hettinger
Change by Raymond Hettinger : -- keywords: +patch pull_requests: +26046 stage: -> patch review pull_request: https://github.com/python/cpython/pull/27536 ___ Python tracker <https://bugs.python.org/issu

[issue27275] KeyError thrown by optimised collections.OrderedDict.popitem()

2021-08-01 Thread Raymond Hettinger
Raymond Hettinger added the comment: > I am not sure how far we should backport these changes > if backport them. We've had no reports of the current code causing problems for any existing applications (except the LRU recipe in the docs), so there is likely no value in makin

[issue43468] functools.cached_property incorrectly locks the entire descriptor on class instead of per-instance locking

2021-08-01 Thread Raymond Hettinger
Raymond Hettinger added the comment: > It is hard to get rid of the execution lock once > it was introduced, but I think we should do it. It's likely some apps are relying on the locking feature. So if we can fix it, we should do prefer that over more disruptive changes. Addenda

[issue27275] KeyError thrown by optimised collections.OrderedDict.popitem()

2021-08-01 Thread Raymond Hettinger
Raymond Hettinger added the comment: Let's do the right thing and fix the pure python OrderedDict.pop() method as well. -- ___ Python tracker <https://bugs.python.org/is

[issue27275] KeyError thrown by optimised collections.OrderedDict.popitem()

2021-08-01 Thread Raymond Hettinger
Raymond Hettinger added the comment: > I think Serhiy's patch here (before revert) may be a > good idea (to re-apply). That seems sensible to me as well. It keeps the C version in harmony with the pure python version and it follows how regular dict's are implemented.

[issue44782] LRU class given as example in OrderedDict docs not work on pop

2021-08-01 Thread Raymond Hettinger
Raymond Hettinger added the comment: Possible replacement recipes: -- Implement as a class - class LRU: def __init__(self, func, maxsize=128): self.func = func self.d = OrderedDict() def __call__(self, *args): if args in self.d

[issue43468] functools.cached_property incorrectly locks the entire descriptor on class instead of per-instance locking

2021-08-01 Thread Raymond Hettinger
Change by Raymond Hettinger : -- nosy: +carljm, ncoghlan, pydanny ___ Python tracker <https://bugs.python.org/issue43468> ___ ___ Python-bugs-list mailin

[issue43468] functools.cached_property incorrectly locks the entire descriptor on class instead of per-instance locking

2021-07-31 Thread Raymond Hettinger
Raymond Hettinger added the comment: Antti Haapala, I agree that this situation is catastrophic and that we need some way to avoid blocking parallel calculations of cached values for distinct instances of the same class. Here's an idea that might possibly work. Perhaps, hold one lock

[issue44782] LRU class given as example in OrderedDict docs not work on pop

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

[issue44782] LRU class given as example in OrderedDict docs not work on pop

2021-07-30 Thread Raymond Hettinger
Raymond Hettinger added the comment: I'm thinking that the current LRU() recipe should be changed to lru_cache() API using an OrderedDict internally rather than inheriting from it. The current recipe was intended to be a sketch rather than a complete class; otherwise, methods lik

[issue44782] LRU class given as example in OrderedDict docs not work on pop

2021-07-30 Thread Raymond Hettinger
Change by Raymond Hettinger : -- assignee: docs@python -> rhettinger nosy: +rhettinger ___ Python tracker <https://bugs.python.org/issue44782> ___ ___ Python-

[issue44773] case_insensitive kwarg in str.replace()

2021-07-29 Thread Raymond Hettinger
Raymond Hettinger added the comment: I don't think this should be done. If case doesn't matter at all, the input can be casefolded before the replacement: s.casefold().replace('hippo', 'giraffe'). If it can't be casefolded in advance because t

[issue44750] .popitem() is inconsistent in collections and collections.abc

2021-07-27 Thread Raymond Hettinger
Raymond Hettinger added the comment: Alex, thank for noticing this, but it is not a bug. MutableMapping is meant to describe all mapping classes including those that don't remember insertion order. The builtin dict() type implements MutableMapping but also adds ordering guarantees.

[issue44605] functools.total_ordering doesn't work with metaclasses

2021-07-25 Thread Raymond Hettinger
Raymond Hettinger added the comment: To add support for metaclasses, replacing 'self.__lt__(other)' with 'type(self).__lt__(self, other)' will work. The performance degradation for the common case is about 25%: $ py -m timeit -s 'from tmp import a, b' 'a

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