[issue46970] dataclass(slots=True) incompatible with __init_subclass__
Change by Guido Imperiale : -- type: -> crash ___ Python tracker <https://bugs.python.org/issue46970> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue46970] dataclass(slots=True) incompatible with __init_subclass__
Change by Guido Imperiale : -- nosy: +eric.smith ___ Python tracker <https://bugs.python.org/issue46970> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue46970] dataclass(slots=True) incompatible with __init_subclass__
New submission from Guido Imperiale : Related to #46382 A class decorated with dataclass(slots=True) can't pass any parameters to the __init_subclass__ method of its parent class. from dataclasses import dataclass class A: __slots__ = () def __init_subclass__(cls, msg): print(msg) @dataclass(slots=True) class B(A, msg="Hello world!"): pass File "lib/python3.10/dataclasses.py", line 1145, in _add_slots cls = type(cls)(cls.__name__, cls.__bases__, cls_dict) TypeError: A.__init_subclass__() missing 1 required positional argument: 'msg' -- components: Library (Lib) messages: 414822 nosy: crusaderky priority: normal severity: normal status: open title: dataclass(slots=True) incompatible with __init_subclass__ versions: Python 3.10 ___ Python tracker <https://bugs.python.org/issue46970> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue39435] pickle: inconsistent arguments pickle.py vs _pickle.c vs docs
New submission from Guido Imperiale : (1) In the documentation for loads(), the name for the first argument of loads is 'bytes_object'. The actual signature, both in pickle.py and _pickle.c, it is instead 'data'. (2) In the documentation and in pickle.py, the default value for the 'buffers' parameter is None. However, in _pickle.c, it is an empty tuple (); this is also reflected by running the interpreter: In [1]: inspect.signature(pickle.loads).parameters['buffers'] Out[1]: Thanks to @hauntsaninja for spotting these in https://github.com/python/typeshed/pull/3636 -- assignee: docs@python components: Documentation, Library (Lib) messages: 360569 nosy: crusaderky, docs@python priority: normal severity: normal status: open title: pickle: inconsistent arguments pickle.py vs _pickle.c vs docs versions: Python 3.8 ___ Python tracker <https://bugs.python.org/issue39435> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue38854] Decorator breaks inspect.getsource
New submission from Guido Imperiale : Python 3.7.5 and 3.8.0 A decorator causes inspect.getsource() to return clipped output: from collections import defaultdict from functools import wraps import inspect def foo(*args): def decorator(func): @wraps(func) def wrapper(): pass return wrapper return decorator @foo(dict(), defaultdict(lambda: 1)) def f(): pass print(inspect.getsource(f)) Output: @foo(dict(), defaultdict(lambda: 1)) Expected output: @foo(dict(), defaultdict(lambda: 1)) def f(): pass These changes to the decorator parameters cause the problem to disappear: - @foo({}, defaultdict(lambda: 1)) - @foo(dict(), defaultdict(list)) -- messages: 356993 nosy: crusaderky priority: normal severity: normal status: open title: Decorator breaks inspect.getsource versions: Python 3.7, Python 3.8 ___ Python tracker <https://bugs.python.org/issue38854> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue38214] __reduce__ API specs for objects with __slots__
New submission from Guido Imperiale : The documentation for the pickle module states, about the 3rd element of the tuple returned by __reduce__: Optionally, the object’s state, which will be passed to the object’s __setstate__() method as previously described. If the object has no such method then, the value must be a dictionary and it will be added to the object’s __dict__ attribute. This doesn't seem correct to me. It should instead read: Optionally, the object’s state, which will be passed to the object’s __setstate__() method as previously described. If the object has no such method, then the value must be: - for objects with only __dict__, a dictionary which will be used to update the object’s __dict__ attribute. - for objects with only __slots__, a tuple of (None, {<__slots__ key>: , ...}) - for objects with both __dict__ and __slots__, a tuple of ({<__dict__ key>: , ...}, {<__slots__ key>: , ...}) -- assignee: docs@python components: Documentation messages: 352728 nosy: crusaderky, docs@python priority: normal severity: normal status: open title: __reduce__ API specs for objects with __slots__ type: behavior versions: Python 3.7, Python 3.8, Python 3.9 ___ Python tracker <https://bugs.python.org/issue38214> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue38105] hash collision when hash(x) == -2 causes many calls to __eq__
Guido Imperiale added the comment: Of course, the chances that in real life a custom object will have hash == -2 are very small. Different story however is for the actual numbers -1 and -2: In [2]: %timeit {-1, -3} 64.2 ns ± 1.41 ns per loop (mean ± std. dev. of 7 runs, 1000 loops each) In [3]: %timeit {-1, -2} 238 ns ± 5.64 ns per loop (mean ± std. dev. of 7 runs, 100 loops each) -- ___ Python tracker <https://bugs.python.org/issue38105> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue38105] hash collision when hash(x) == -2 causes many calls to __eq__
Guido Imperiale added the comment: Forgot a counter-example: {C(1, 0), C(2, 0)} C((1, 0)).__hash__ C((2, 0)).__hash__ C((1, 0)).__eq__(C((2, 0))) {C((1, 0)), C((2, 0))} -- ___ Python tracker <https://bugs.python.org/issue38105> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue38105] hash collision when hash(x) == -2 causes many calls to __eq__
New submission from Guido Imperiale : Take two objects where hash(a) == hash(b) == -2 exactly, but a != b, When they are inserted in a dict or set, the __eq__ method is invoked a whopping 13 times. Does this have something to do with the special case of hash(-1) = -2? class C: def __init__(self, x, h): self.x = x self.h = h def __eq__(self, other): print(f"{self}.__eq__({other})") return self.x == other.x def __hash__(self): print(f"{self}.__hash__") return self.h def __repr__(self): return f"C({self.x, self.h})" >>> {C(1, -2), C(2, -2)} C((1, -2)).__hash__ C((2, -2)).__hash__ C((1, -2)).__eq__(C((2, -2))) C((1, -2)).__eq__(C((2, -2))) C((1, -2)).__eq__(C((2, -2))) C((1, -2)).__eq__(C((2, -2))) C((1, -2)).__eq__(C((2, -2))) C((1, -2)).__eq__(C((2, -2))) C((1, -2)).__eq__(C((2, -2))) C((1, -2)).__eq__(C((2, -2))) C((1, -2)).__eq__(C((2, -2))) C((1, -2)).__eq__(C((2, -2))) C((1, -2)).__eq__(C((2, -2))) C((1, -2)).__eq__(C((2, -2))) C((1, -2)).__eq__(C((2, -2))) {C((1, -2)), C((2, -2))} >>> {C(1, -3), C(1, -3)} C((1, -3)).__hash__ C((1, -3)).__hash__ C((1, -3)).__eq__(C((1, -3))) {C((1, -3))} >>> {C(1, -1), C(1, -1)} C((1, -1)).__hash__ C((1, -1)).__hash__ C((1, -1)).__eq__(C((1, -1))) >>> {C(1, -2), C(1, -2)} C((1, -2)).__hash__ C((1, -2)).__hash__ C((1, -2)).__eq__(C((1, -2))) {C((1, -2))} -- messages: 351798 nosy: crusaderky priority: normal severity: normal status: open title: hash collision when hash(x) == -2 causes many calls to __eq__ type: performance versions: Python 3.7, Python 3.8 ___ Python tracker <https://bugs.python.org/issue38105> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue36456] task.cancel unbound recursion
Change by Guido Imperiale : -- nosy: +crusaderky ___ Python tracker <https://bugs.python.org/issue36456> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com