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

Add type annotations to various functions within distributed.worker #5290

Merged
merged 6 commits into from
Sep 14, 2021
Merged

Add type annotations to various functions within distributed.worker #5290

merged 6 commits into from
Sep 14, 2021

Conversation

orf
Copy link
Contributor

@orf orf commented Aug 30, 2021

  • Tests added / passed
  • Passes black distributed / flake8 distributed / isort distributed

This is my first contribution to this project, so I hope that it is OK! I've added type hints to get_client(), the lack of which I found quite annoying when starting with Dask.

I also added type hints to some other simple functions, and fixed a potential undefined local variable issue in get_profile_metadata. I also removed some mutable default arguments, and added .venv/ to the .gitignore.

Please let me know if these are acceptable, or if you'd like any removed/changed!

@GPUtester
Copy link
Collaborator

Can one of the admins verify this patch?

Copy link
Member

@jrbourbeau jrbourbeau left a comment

Choose a reason for hiding this comment

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

Thanks for contributing @orf. cc @crusaderky in case you get a chance to look at this

distributed/worker.py Outdated Show resolved Hide resolved
@@ -3259,8 +3267,7 @@ async def get_profile(
return prof

async def get_profile_metadata(self, comm=None, start=0, stop=None):
if stop is None:
add_recent = True
add_recent = stop is None
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could you instead directly change to if stop is None: on line 3284?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The line below this overwrites stop: stop = stop or now. I'm not clear on what these arguments do, but this would always make the condition true.

distributed/worker.py Outdated Show resolved Hide resolved
distributed/worker.py Outdated Show resolved Hide resolved
distributed/worker.py Outdated Show resolved Hide resolved
distributed/worker.py Outdated Show resolved Hide resolved
distributed/worker.py Outdated Show resolved Hide resolved
orf and others added 3 commits August 31, 2021 10:09
Copy link
Member

@jrbourbeau jrbourbeau left a comment

Choose a reason for hiding this comment

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

Thanks for the updates @orf! It looks like there is an ImportError in CI and the linting checks want to make code style updates.

For linting, you can see what checks are run here https://docs.dask.org/en/latest/develop.html#code-formatting. I'd recommend installing the optional pre-commit hooks to ensure these checks are always run locally prior to pushing up commits to GitHub.

@orf
Copy link
Contributor Author

orf commented Aug 31, 2021

Thanks for the suggestions! I've applied them. Sorry about the CI failures, I applied some suggestions directly from Github and I've only had time to do the other manual changes now.

@crusaderky
Copy link
Collaborator

LGTM

@orf
Copy link
Contributor Author

orf commented Sep 3, 2021

Is there anything I need to do to get this merged? It's unfortunate that it missed the 2021.09.0 release, as our users have been asking for this.

The CI failure appears to be unrelated

@crusaderky
Copy link
Collaborator

@jrbourbeau please merge

Copy link
Member

@jrbourbeau jrbourbeau left a comment

Choose a reason for hiding this comment

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

Thanks for the updates @orf and reviewing @crusaderky!

Also, @orf I noticed this is your first code contribution to this repository. Welcome!

@jrbourbeau jrbourbeau merged commit 3f86e58 into dask:main Sep 14, 2021
@orf orf deleted the add-type-annotations branch September 14, 2021 20:25
@orf
Copy link
Contributor Author

orf commented Sep 14, 2021

Thank you! I'll go through and add some more annotations soon, there are some heavily used user-facing functions that could benefit a lot from it.

I don't know the best place to ask this, but would you also accept contributions that added __class_getitem__ methods so we could do Future[int] or somesuch in our annotations?

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.

4 participants