Skip to content
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

Fix Process.communicate() return type #13384

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Dreamsorcerer
Copy link
Contributor

@Dreamsorcerer Dreamsorcerer commented Jan 10, 2025

With mypyc I get:

Traceback (most recent call last):
  File "bluetooth_devices.py", line 216, in switch_to_master
    while await self.is_slave(device_address):
  File "bluetooth_devices.py", line 231, in is_slave
    stdout, stderr = await proc.communicate()
TypeError: tuple[bytes, bytes] object expected; got tuple[bytes, None]

From the docs:

to get anything other than None in the result tuple, the process has to be created with stdout=PIPE and/or stderr=PIPE arguments.

This could be more precise if the Process was Generic and the type depended on the arguments passed..

Copy link
Contributor

Diff from mypy_primer, showing the effect of this PR on open source code:

aiohttp-devtools (https://github.com/aio-libs/aiohttp-devtools)
+ tests/test_runserver_cleanup.py:40: error: Unsupported right operand type for in ("bytes | None")  [operator]
+ tests/test_runserver_cleanup.py:41: error: Item "None" of "bytes | None" has no attribute "decode"  [union-attr]

core (https://github.com/home-assistant/core)
+ homeassistant/util/package.py:186: error: Item "None" of "bytes | None" has no attribute "decode"  [union-attr]
+ homeassistant/components/command_line/utils.py:60: error: Item "None" of "bytes | None" has no attribute "strip"  [union-attr]
+ homeassistant/auth/providers/command_line.py:95: error: Item "None" of "bytes | None" has no attribute "splitlines"  [union-attr]

@Dreamsorcerer
Copy link
Contributor Author

I can add assert is not None to the affected code, or look at making it Generic?

@Dreamsorcerer
Copy link
Contributor Author

I started an attempt to make it generic in #13385, but I think it'll be fairly complex to get working.

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.

1 participant