"open" in globals()["__builtins__"], an error occurs: "TypeError: argument of type 'module' is not iterable"
NONE
@kuanyan9527 Your query is indeed valid. Following could be its reasoning:

Quoting from https://stackoverflow.com/a/11181607:
"By default, when in the `__main__` module,` __builtins__` is the built-in module `__builtin__` (note: no 's'); when in any other module, `__builtins__` is an alias for the dictionary of the `__builtin__` module itself."

Can you confirm if you are running the snippet `print("open" in globals()["__builtins__"])` in the default? In that case, as expected, `__builtins__` is a module which is causing the error. But in the codebase, the class `patch_submodule`, is primarily used in the second circumstance, where it acts as a dictionary. Hence causing the code to function successfully.

Hope this helps.
2025-06-27T17:38:28Z
https://github.com/huggingface/datasets/issues/7636#issuecomment-3013895491
https://api.github.com/repos/huggingface/datasets/issues/7636
IC_kwDODunzps6zpGVD
https://api.github.com/repos/huggingface/datasets/issues/comments/3013895491/reactions
2025-06-27T17:38:28Z
https://api.github.com/repos/huggingface/datasets/issues/comments/3013895491
https://avatars.githubusercontent.com/u/106822488?v=4
https://api.github.com/users/SP1029/events{/privacy}
https://api.github.com/users/SP1029/followers
https://api.github.com/users/SP1029/following{/other_user}
https://api.github.com/users/SP1029/gists{/gist_id}
https://github.com/SP1029
SP1029
U_kgDOBl37WA
https://api.github.com/users/SP1029/orgs
https://api.github.com/users/SP1029/received_events
https://api.github.com/users/SP1029/repos
https://api.github.com/users/SP1029/starred{/owner}{/repo}
https://api.github.com/users/SP1029/subscriptions
User
https://api.github.com/users/SP1029
public
NONE
@kuanyan9527 Are there any more queries in this regards, else please feel free to close the issue.
Thank you.
2025-06-30T15:40:57Z
https://github.com/huggingface/datasets/issues/7636#issuecomment-3019686005
https://api.github.com/repos/huggingface/datasets/issues/7636
IC_kwDODunzps6z_MB1
https://api.github.com/repos/huggingface/datasets/issues/comments/3019686005/reactions
2025-06-30T15:40:57Z
https://api.github.com/repos/huggingface/datasets/issues/comments/3019686005
https://avatars.githubusercontent.com/u/106822488?v=4
https://api.github.com/users/SP1029/events{/privacy}
https://api.github.com/users/SP1029/followers
https://api.github.com/users/SP1029/following{/other_user}
https://api.github.com/users/SP1029/gists{/gist_id}
https://github.com/SP1029
SP1029
U_kgDOBl37WA
https://api.github.com/users/SP1029/orgs
https://api.github.com/users/SP1029/received_events
https://api.github.com/users/SP1029/repos
https://api.github.com/users/SP1029/starred{/owner}{/repo}
https://api.github.com/users/SP1029/subscriptions
User
https://api.github.com/users/SP1029
public
NONE
Your answer is very important to me,thanks.
2025-07-01T01:54:05Z
https://github.com/huggingface/datasets/issues/7636#issuecomment-3021429341
https://api.github.com/repos/huggingface/datasets/issues/7636
IC_kwDODunzps60F1pd
https://api.github.com/repos/huggingface/datasets/issues/comments/3021429341/reactions
2025-07-01T01:54:05Z
https://api.github.com/repos/huggingface/datasets/issues/comments/3021429341
https://avatars.githubusercontent.com/u/51187979?v=4
https://api.github.com/users/kuanyan9527/events{/privacy}
https://api.github.com/users/kuanyan9527/followers
https://api.github.com/users/kuanyan9527/following{/other_user}
https://api.github.com/users/kuanyan9527/gists{/gist_id}
https://github.com/kuanyan9527
kuanyan9527
MDQ6VXNlcjUxMTg3OTc5
https://api.github.com/users/kuanyan9527/orgs
https://api.github.com/users/kuanyan9527/received_events
https://api.github.com/users/kuanyan9527/repos
https://api.github.com/users/kuanyan9527/starred{/owner}{/repo}
https://api.github.com/users/kuanyan9527/subscriptions
User
https://api.github.com/users/kuanyan9527
public
NONE
I encountered this error when running datasets with pypy,
`TypeError: argument of type 'module' is not iterable` in [src/datasets/utils/patching.py#L96](https://github.com/huggingface/datasets/blob/3.6.0/src/datasets/utils/patching.py#L96)
by modifying `globals()["__builtins__"]` to `builtins.__dict__`, importing via `import builtins`.
Can this be applied to the community?
2025-07-10T04:13:16Z
https://github.com/huggingface/datasets/issues/7636#issuecomment-3055318364
https://api.github.com/repos/huggingface/datasets/issues/7636
IC_kwDODunzps62HHVc
https://api.github.com/repos/huggingface/datasets/issues/comments/3055318364/reactions
2025-07-10T04:13:16Z
https://api.github.com/repos/huggingface/datasets/issues/comments/3055318364
https://avatars.githubusercontent.com/u/51187979?v=4
https://api.github.com/users/kuanyan9527/events{/privacy}
https://api.github.com/users/kuanyan9527/followers
https://api.github.com/users/kuanyan9527/following{/other_user}
https://api.github.com/users/kuanyan9527/gists{/gist_id}
https://github.com/kuanyan9527
kuanyan9527
MDQ6VXNlcjUxMTg3OTc5
https://api.github.com/users/kuanyan9527/orgs
https://api.github.com/users/kuanyan9527/received_events
https://api.github.com/users/kuanyan9527/repos
https://api.github.com/users/kuanyan9527/starred{/owner}{/repo}
https://api.github.com/users/kuanyan9527/subscriptions
User
https://api.github.com/users/kuanyan9527
public
When I run the following code, an error occurs: "TypeError: argument of type 'module' is not iterable"
```python
print("open" in globals()["__builtins__"])
```
Traceback (most recent call last):
  File "./main.py", line 2, in <module>
    print("open" in globals()["__builtins__"])
          ^^^^^^^^^^^^^^^^^^^^^^
TypeError: argument of type 'module' is not iterable

But this code runs fine in datasets, I don't understand why
[src/datasets/utils/patching.py#L96](https://github.com/huggingface/datasets/blob/3.6.0/src/datasets/utils/patching.py#L96)