Karthikeyan Singaravelan <tir.kar...@gmail.com> added the comment:

https://docs.python.org/3/library/unittest.mock.html#unittest.mock.Mock

> spec: This can be either a list of strings or an existing object (a class or 
> instance) that acts as the specification for the mock object. If you pass in 
> an object then a list of strings is formed by calling dir on the object 
> (excluding unsupported magic attributes and methods). Accessing any attribute 
> not in this list will raise an AttributeError.

Docs state it should be list of strings. Can you please link to docs where an 
iterable of strings is mentioned? A simple patch would be to wrap it inside a 
list() call but I am not sure of making the interface more relaxed which was 
documented to accept list of strings. I am adding module mock devs to take a 
call on this.


diff --git a/Lib/unittest/mock.py b/Lib/unittest/mock.py
index 8684f1dfa5..35dc7b044e 100644
--- a/Lib/unittest/mock.py
+++ b/Lib/unittest/mock.py
@@ -679,7 +679,7 @@ class NonCallableMock(Base):
         if not FILTER_DIR:
             return object.__dir__(self)

-        extras = self._mock_methods or []
+        extras = list(self._mock_methods or [])
         from_type = dir(type(self))
         from_dict = list(self.__dict__)

----------
nosy: +cjw296, mariocj89, michael.foord, xtreak

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

Reply via email to