@@ -200,23 +200,34 @@ def verify_mypyfile(
200
200
yield Error (object_path , "is not a module" , stub , runtime )
201
201
return
202
202
203
- # Check things in the stub that are public
203
+ # Check things in the stub
204
204
to_check = set (
205
205
m
206
206
for m , o in stub .names .items ()
207
- # TODO: change `o.module_public` to `not o.module_hidden`
208
- if o .module_public and (not m .startswith ("_" ) or hasattr (runtime , m ))
207
+ if not o .module_hidden and (not m .startswith ("_" ) or hasattr (runtime , m ))
209
208
)
210
- runtime_public_contents = [
211
- m
212
- for m in dir (runtime )
213
- if not m .startswith ("_" )
214
- # Ensure that the object's module is `runtime`, since in the absence of __all__ we don't
215
- # have a good way to detect re-exports at runtime.
216
- and getattr (getattr (runtime , m ), "__module__" , None ) == runtime .__name__
217
- ]
218
- # Check all things declared in module's __all__, falling back to runtime_public_contents
219
- to_check .update (getattr (runtime , "__all__" , runtime_public_contents ))
209
+
210
+ def _belongs_to_runtime (r : types .ModuleType , attr : str ) -> bool :
211
+ obj = getattr (r , attr )
212
+ obj_mod = getattr (obj , "__module__" , None )
213
+ if obj_mod is not None :
214
+ return obj_mod == r .__name__
215
+ return not isinstance (obj , types .ModuleType )
216
+
217
+ runtime_public_contents = (
218
+ runtime .__all__
219
+ if hasattr (runtime , "__all__" )
220
+ else [
221
+ m
222
+ for m in dir (runtime )
223
+ if not m .startswith ("_" )
224
+ # Ensure that the object's module is `runtime`, since in the absence of __all__ we
225
+ # don't have a good way to detect re-exports at runtime.
226
+ and _belongs_to_runtime (runtime , m )
227
+ ]
228
+ )
229
+ # Check all things declared in module's __all__, falling back to our best guess
230
+ to_check .update (runtime_public_contents )
220
231
to_check .difference_update ({"__file__" , "__doc__" , "__name__" , "__builtins__" , "__package__" })
221
232
222
233
for entry in sorted (to_check ):
0 commit comments