[issue37479] IntEnum f-string behavior can't be overridden
New submission from Jason Curtis : Combining int and Enum, as with enum.IntEnum results in a class where __str__ cannot be effectively overridden. For example: from enum import IntEnum class myIntEnum(IntEnum): x = 1 def __str__(self): return 'AAAa' f'{myIntEnum.x}, {str(myIntEnum.x)}' Expected output: 'AAAa, AAAa' Actual output: '1, AAAa' Overriding __str__ in this way works as expected if the inherited classes are int or Enum individually. However, it does not work when inheriting (int, Enum) or when inheriting (intEnum). Presumably this is a side effect of Enum's mixin behavior documented at https://docs.python.org/3/library/enum.html#others and it is possibly related to https://bugs.python.org/issue18264 . -- components: Library (Lib) messages: 347089 nosy: Jason Curtis priority: normal severity: normal status: open title: IntEnum f-string behavior can't be overridden type: behavior versions: Python 3.6 ___ Python tracker <https://bugs.python.org/issue37479> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue37479] IntEnum f-string behavior can't be overridden
Jason Curtis added the comment: I mistyped - __str__ can be overridden effectively, but __format__ has to be overridden instead or overridden also to get the desired f-string behavior. -- ___ Python tracker <https://bugs.python.org/issue37479> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue37479] IntEnum f-string behavior can't be overridden
Jason Curtis added the comment: related cPython code: https://github.com/python/cpython/blob/19a1e1eb86115db66c1faae5927f87e3a12692fc/Lib/enum.py#L626 If we're in a mixed-in class but the class has overridden __str__(), we should probably use str(self) instead of self._value_. -- ___ Python tracker <https://bugs.python.org/issue37479> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue37479] IntEnum __format__ behavior can't be overridden through __str__
Change by Jason Curtis : -- title: IntEnum f-string behavior can't be overridden -> IntEnum __format__ behavior can't be overridden through __str__ ___ Python tracker <https://bugs.python.org/issue37479> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue37770] reversed class should implement __reversed__
New submission from Jason Curtis : I've just been trying to implement some logic which potentially involves reversing things back to their initial orders, and it'd be nice to just be able to call reversed() on something that has already been reversed. >>> reversed(reversed([1,2,3,4])) TypeError: 'list_reverseiterator' object is not reversible Seems like this should be trivial to implement by just returning the initial iterator. Happy to post a pull request if it would be considered. -- components: Library (Lib) messages: 349085 nosy: jason.curtis priority: normal severity: normal status: open title: reversed class should implement __reversed__ type: enhancement versions: Python 3.7 ___ Python tracker <https://bugs.python.org/issue37770> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue37770] reversed class should implement __reversed__
Jason Curtis added the comment: Ok, not so sure about the PR now; I dug around and realized this is a C implementation and my C is likely not strong enough! -- ___ Python tracker <https://bugs.python.org/issue37770> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue37770] implement __reversed__ on reversed types
Change by Jason Curtis : -- title: reversed class should implement __reversed__ -> implement __reversed__ on reversed types ___ Python tracker <https://bugs.python.org/issue37770> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue29229] incompatible: unittest.mock.sentinel and multiprocessing.Pool.map()
New submission from Jason Curtis: When a sentinel object from unittest.mock.sentinel is passed through a multiprocessing.Pool.map, I expect it to still be comparable. As a user, I'd like to be able to write a unit test using sentinels on my unparallelized code, and then see that the test still passes after I parallelize the code using multiprocessing, so that I can make use of sentinels in regression testing. Example: ``` from unittest import mock import multiprocessing def identity(x): return x with multiprocessing.Pool() as pool: multiprocessed = list(pool.map(identity, [mock.sentinel.foo])) assert identity(mock.sentinel.foo) == mock.sentinel.foo # Passes assert multiprocessed[0] == mock.sentinel.foo # Fails ``` -- components: Library (Lib) messages: 285146 nosy: Jason Curtis priority: normal severity: normal status: open title: incompatible: unittest.mock.sentinel and multiprocessing.Pool.map() type: behavior versions: Python 3.4 ___ Python tracker <http://bugs.python.org/issue29229> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue29229] incompatible: unittest.mock.sentinel and multiprocessing.Pool.map()
Jason Curtis added the comment: sounds right; closing as a duplicate of issue20804 -- resolution: -> duplicate status: open -> closed ___ Python tracker <http://bugs.python.org/issue29229> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue22955] Pickling of methodcaller, attrgetter, and itemgetter
Jason Curtis added the comment: This is still an issue with operator.attrgetter in 3.4.3, even after clearing sys.modules['_operator']: $ python3 Python 3.4.3 (default, Oct 14 2015, 20:28:29) [GCC 4.8.4] on linux Type "help", "copyright", "credits" or "license" for more information. >>> import sys >>> sys.modules['_operator'] = None >>> import operator >>> import pickle >>> pickle.loads(pickle.dumps(operator.attrgetter("foo"))) Traceback (most recent call last): File "", line 1, in _pickle.PicklingError: Can't pickle .func at 0x7f25728d5bf8>: attribute lookup func on operator failed -- nosy: +Jason Curtis versions: +Python 3.4 ___ Python tracker <http://bugs.python.org/issue22955> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com