Skip to content

Fix shared type in _interpreters #14328

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open

Fix shared type in _interpreters #14328

wants to merge 5 commits into from

Conversation

sobolevn
Copy link
Member

It is a dict[str, Any] or None:

>>> import _interpreters
>>> i = _interpreters.create()

>>> _interpreters.exec(i, 'print(1)', shared=False)
Traceback (most recent call last):
  File "<python-input-3>", line 1, in <module>
    _interpreters.exec(i, 'print(1)', shared=False)
    ~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: _interpreters.exec() argument 3 must be dict, not bool

Non-str keys:

>>> _interpreters.exec(i, 'print(1)', shared={1: 1})
Traceback (most recent call last):
  File "<python-input-4>", line 1, in <module>
    _interpreters.exec(i, 'print(1)', shared={1: 1})
    ~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: bad argument type for built-in operation

Real sharing:

>>> _interpreters.exec(i, 'print(1)', shared={'a': 1})
1

Some objects can't be shared. Currently only a few can be. But, I think that restricting this type yet is not a good idea, because more can be added in the future. Also, (1, 2) is ok, (1, object()) is not

sobolevn and others added 3 commits June 23, 2025 15:34
It is a `dict[str, Any]` or `None`:

```python
>>> import _interpreters
>>> i = _interpreters.create()

>>> _interpreters.exec(i, 'print(1)', shared=False)
Traceback (most recent call last):
  File "<python-input-3>", line 1, in <module>
    _interpreters.exec(i, 'print(1)', shared=False)
    ~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: _interpreters.exec() argument 3 must be dict, not bool
```

Non-`str` keys:

```python
>>> _interpreters.exec(i, 'print(1)', shared={1: 1})
Traceback (most recent call last):
  File "<python-input-4>", line 1, in <module>
    _interpreters.exec(i, 'print(1)', shared={1: 1})
    ~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: bad argument type for built-in operation
```

Real sharing:

```python
>>> _interpreters.exec(i, 'print(1)', shared={'a': 1})
1
```

Some objects can't be shared. Currently only a few can be. But, I think that restricting this type yet is not a good idea, because more can be added in the future. Also, `(1, 2)` is ok, `(1, object())` is not

This comment has been minimized.

Copy link
Member

@brianschubert brianschubert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(I suppose the last example should be _interpreters.exec(i, 'print(a)', shared={'a': 1}) ;)

Copy link
Contributor

According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants