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

[th/mypy] fix typing annotations so that mypy --strict passes and enable github action #24

Merged
merged 4 commits into from
Oct 2, 2024

Conversation

thom311
Copy link
Contributor

@thom311 thom311 commented Sep 12, 2024

  • fixes so that mypy passes (mostly type annotations)
  • enable mypy in github actions
  • common_bf.run() needs to switch from a Result namedtuple to a dataclass. The reason is, that with dataclasses mypy understands the types (alternatively, we could use typing.NamedTuple, but a dataclass works well).
  • while reworking common_bf.run(), also switch it over to subprocess.run(). The reimplementation with Popen() was not correct (because it reads stdout to the end, if a process prints a lot to stderr, it will block).
  • copy common_bf.run() over to dpu-tools.run(). It's the same thing (also needing changes to work with mypy checks), and should use the same code.

The pattern

  out = proc.stdout.read().decode("utf-8")
  err = proc.stderr.read().decode("utf-8")

is broken, because we won't read stderr before stdout is fully read.
That means, if the command writes a lot to stderr, then the pipe will
block writing and hang the process.

Use subprocess.run(), which gets this right.
With namedtuple, mypy doesn't understand the types of the fields.
Use a dataclass instead.
This is copied over from common_bf.run(). The difference is that it better
handles typing.

Later, we should not copy code around but re-use code (e.g. by importing
the common_bf module). But for now, it is still copied because to import
the code we also need to ensure that we include the common_bf module.
@bn222 bn222 merged commit ae97860 into bn222:main Oct 2, 2024
1 check passed
@thom311 thom311 deleted the th/mypy branch October 2, 2024 09:44
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