File tree Expand file tree Collapse file tree 1 file changed +11
-5
lines changed Expand file tree Collapse file tree 1 file changed +11
-5
lines changed Original file line number Diff line number Diff line change 58
58
def discover (
59
59
package : ModuleType ,
60
60
match_func : Optional [Callable [[Any ], bool ]] = None ,
61
+ exclude_side_effects : bool = True ,
61
62
) -> List [Type [Any ]]:
62
63
"""
63
64
Returns a list of objects in the directory matched by ``match_func``.
64
65
65
66
:param package: A Python package
66
67
:param match_func: Function taking an object and returning true if the object is to be included in the output.
67
68
:default match_func: :py:obj:`None`, which includes all objects.
69
+ :param exclude_side_effects: Don't include objects that are only there because of an import side effect.
68
70
69
71
:return: List of matching objects.
72
+
73
+ .. versionchanged:: 1.0.0
74
+
75
+ Added the ``exclude_side_effects`` parameter.
70
76
"""
71
77
72
78
matched_classes = list ()
@@ -82,12 +88,12 @@ def discover(
82
88
83
89
# Check all the functions in that module
84
90
for _ , imported_objects in inspect .getmembers (module , match_func ):
85
- if not hasattr (imported_objects , "__module__" ):
86
- continue
87
91
88
- # Don't include things that are only there due to a side effect of importing
89
- if imported_objects .__module__ != module .__name__ :
90
- continue
92
+ if exclude_side_effects :
93
+ if not hasattr (imported_objects , "__module__" ):
94
+ continue
95
+ if imported_objects .__module__ != module .__name__ :
96
+ continue
91
97
92
98
matched_classes .append (imported_objects )
93
99
You can’t perform that action at this time.
0 commit comments