[issue45215] Add docs for Mock name and parent args and deprecation warning when wrong args are passed

2021-09-21 Thread Andrei Kulakov
Andrei Kulakov added the comment: Łukasz: For parent, there's this issue: #39222 (which is why I started looking into this). For name, I couldn't find anything here or on SO, but it's hard to search for this because keywords 'mock argument name' on SO finds over 700 results but they're

[issue45215] Add docs for Mock name and parent args and deprecation warning when wrong args are passed

2021-09-21 Thread Łukasz Langa
Łukasz Langa added the comment: Have you encountered misuse of Mock's `name` and `parent` in the wild? As you're saying, since `str()` and `repr()` will error out anyway, it's unlikely users were doing this in the first place. I'm a little hesitant to accept the deprecation since there are

[issue45215] Add docs for Mock name and parent args and deprecation warning when wrong args are passed

2021-09-16 Thread Andrei Kulakov
Andrei Kulakov added the comment: I forgot to include example of the breakage: >>> m=Mock(name=1) >>> m Traceback (most recent call last): File "", line 1, in File "/Users/ak/opensource/cpython2/Lib/unittest/mock.py", line 735, in __repr__ name = self._extract_mock_name()

[issue45215] Add docs for Mock name and parent args and deprecation warning when wrong args are passed

2021-09-15 Thread Andrei Kulakov
Change by Andrei Kulakov : -- keywords: +patch pull_requests: +26793 stage: -> patch review pull_request: https://github.com/python/cpython/pull/28378 ___ Python tracker ___

[issue45215] Add docs for Mock name and parent args and deprecation warning when wrong args are passed

2021-09-15 Thread Andrei Kulakov
New submission from Andrei Kulakov : Currently using *name* and *parent* args in Mock and MagicMock is problematic in a few ways: *name* - any value can be passed silently but at a later time, any value except for an str will cause an exception when repr() or str() on the mock object is