[issue45756] mock raises exception when using a spec with an attribute that raises exception on access
New submission from Kevin Jamieson : In Python 3.8 and later creating a mock with a spec specifying an object containing a property that happens to raise an exception when accessed will fail, because _mock_add_spec calls getattr() on every attribute of the spec. This did not happen in Python 3.6/3.7. This is likely a fairly unusual scenario (and in the particular case where I encountered this I could just use a class instead of an instance for the spec), but it was surprising. For example: # cat test.py from unittest import mock class Foo: @property def bar(self) -> str: raise Exception('xxx') m = mock.MagicMock(spec=Foo()) # python3.11 test.py Traceback (most recent call last): File "/root/test.py", line 8, in m = mock.MagicMock(spec=Foo()) ^^ File "/usr/lib/python3.11/unittest/mock.py", line 2069, in __init__ _safe_super(MagicMixin, self).__init__(*args, **kw) ^^^ File "/usr/lib/python3.11/unittest/mock.py", line 1087, in __init__ _safe_super(CallableMixin, self).__init__( ^^ File "/usr/lib/python3.11/unittest/mock.py", line 442, in __init__ self._mock_add_spec(spec, spec_set, _spec_as_instance, _eat_self) ^ File "/usr/lib/python3.11/unittest/mock.py", line 497, in _mock_add_spec if iscoroutinefunction(getattr(spec, attr, None)): ^ File "/root/test.py", line 6, in bar raise Exception('xxx') ^^ Exception: xxx -- messages: 405982 nosy: kjamieson priority: normal severity: normal status: open title: mock raises exception when using a spec with an attribute that raises exception on access type: behavior versions: Python 3.10, Python 3.11, Python 3.8, Python 3.9 ___ Python tracker <https://bugs.python.org/issue45756> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue45755] Mock spec with a specialized generic class does not mock class attributes
New submission from Kevin Jamieson : This worked in Python 3.6, but in Python 3.7 and later creating a mock with a spec specifying a subscripted generic class does not mock any of the attributes of the class, because those attributes are not returned by dir(). For example: # cat test.py from typing import Generic, TypeVar from unittest import mock T = TypeVar('T') class Foo(Generic[T]): def bar(self) -> None: pass m = mock.MagicMock(spec=Foo[int]) m.bar() # python3.11 test.py Traceback (most recent call last): File "/root/test.py", line 11, in m.bar() ^^^ File "/usr/lib/python3.11/unittest/mock.py", line 635, in __getattr__ raise AttributeError("Mock object has no attribute %r" % name) ^^ AttributeError: Mock object has no attribute 'bar' -- components: Library (Lib) messages: 405981 nosy: kjamieson priority: normal severity: normal status: open title: Mock spec with a specialized generic class does not mock class attributes type: behavior versions: Python 3.10, Python 3.11, Python 3.7, Python 3.8, Python 3.9 ___ Python tracker <https://bugs.python.org/issue45755> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
tkinter and widget placement after resizing
Hello, I've got a fairly simple GUI that places pmw.EntryFields into a window starting in the upper left corner. When the first column is filled with these widgets I'd like to start a new column and continue placement, and so on. It is working now with the grid manager if I explicitly set the max number of widgets per column, but if I resize the main window there is wasted space as the number of widgets per column is fixed. I'd like to find a design that could change the number of widgets per column when the window is resized. Any suggestions? i.e. start out with a window like this: [1][4][7] [2][5][8] [3][6][9] make the main window larger and end up with this: [1][6] [2][7] [3][8] [4][9] [5] -- http://mail.python.org/mailman/listinfo/python-list