[issue36581] __dir__ on unittest.mock not safe for all spec types

2019-04-09 Thread Dylan Semler

New submission from Dylan Semler :

If a MagicMock is created with a spec or spec_set that is a non-list iterable 
of strings (like a tuple), calling dir() on said mock produces a Traceback.  
Here's a minimum example:

🡒 cat poc.py
from unittest.mock import MagicMock

mock = MagicMock(spec=('a', 'tuple'))
dir(mock)

🡒 python3 poc.py 
Traceback (most recent call last):
  File "poc.py", line 4, in 
dir(mock)
  File "/usr/lib64/python3.6/unittest/mock.py", line 677, in __dir__
return sorted(set(extras + from_type + from_dict +
TypeError: can only concatenate tuple (not "list") to tuple

--
components: Library (Lib)
messages: 339813
nosy: Dylan Semler
priority: normal
severity: normal
status: open
title: __dir__ on unittest.mock not safe for all spec types
type: crash
versions: Python 3.6, Python 3.7, Python 3.8

___
Python tracker 
<https://bugs.python.org/issue36581>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue36581] __dir__ on unittest.mock not safe for all spec types

2019-04-09 Thread Dylan Semler


Dylan Semler  added the comment:

I agree docs only say "list of strings" and so this isn't a case where there's 
behavior that contrasts with the documentation. I merely ran into this issue in 
my project and found it difficult to get to the root of so wanted to fix it 
upstream. I made a patch and reported this bug only as a formality to accompany 
my patch.

--

___
Python tracker 
<https://bugs.python.org/issue36581>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com