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

Review annotations and docstrings in scheduler.py, part 1 #6132

Merged
merged 4 commits into from
Apr 19, 2022

Conversation

crusaderky
Copy link
Collaborator

@crusaderky crusaderky commented Apr 15, 2022

Follow-up to #6104

Incomplete work (I reached WorkerState, included). It can be merged as-is; more PRs will follow when time allows.

.. attribute:: client_key: str
#: A unique identifier for this client. This is generally an opaque
#: string generated by the client itself.
client_key: str
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I added :members: to worker-memory.rst. This means that attributes, methods, and properties that have a docstring and don't start with _ are now automatically documented.

@@ -196,21 +195,26 @@ def _to_dict_no_nest(self, *, exclude: "Container[str]" = ()) -> dict:

class MemoryState:
"""Memory readings on a worker or on the whole cluster.
See :doc:`worker-memory`.
Copy link
Collaborator Author

@crusaderky crusaderky Apr 15, 2022

Choose a reason for hiding this comment

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

This class is now documented in Sphinx. It was already referenced in public docs in several places.

Copy link
Member

Choose a reason for hiding this comment

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

Historically we've kept a newline between the title line of a docstring and the body. Thoughts on this? Any objection to continuing with it?

I don't care so much about this particular instance (please don't block on a comment this small), but more broadly I'd love to align on this if it's easy.

https://docs.dask.org/en/stable/develop.html#docstrings

will run them eventually, depending on its execution resources
(but see :doc:`work-stealing`).
local_directory: str
services: dict[str, int]
Copy link
Collaborator Author

@crusaderky crusaderky Apr 15, 2022

Choose a reason for hiding this comment

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

These attributes were undocumented before and remain it now.
Note that our definition of "public" is "documented in Sphinx". This makes these attributes implicitly private.

There should be a proper pass later on where we document these attributes and decide wether we want to prepend them with _ to hide them from sphinx again - and make it clear that they're private.

#: History of the last 30 seconds' worth of unmanaged memory. Used to differentiate
#: between "old" and "new" unmanaged memory.
#: Format: ``[(timestamp, bytes), (timestamp, bytes), ...]``
_memory_unmanaged_history: deque[tuple[float, int]]
Copy link
Collaborator Author

@crusaderky crusaderky Apr 15, 2022

Choose a reason for hiding this comment

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

These two attributes were undocumented (and thus private before), and I felt they should remain private, so I prepended them with _.

@@ -569,7 +584,7 @@ def identity(self) -> dict:
**self.extra,
}

def _to_dict_no_nest(self, *, exclude: "Container[str]" = ()) -> dict:
def _to_dict_no_nest(self, *, exclude: Container[str] = ()) -> dict[str, Any]:
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The thorough review ends here. Beyond this point it's either auto-tweaks by pyupgrade or fixes to keep things working.

@crusaderky crusaderky self-assigned this Apr 15, 2022
@github-actions
Copy link
Contributor

github-actions bot commented Apr 15, 2022

Unit Test Results

       16 files  +       4         16 suites  +4   7h 20m 21s ⏱️ + 1h 50m 24s
  2 742 tests +       3    2 659 ✔️ +     11       80 💤  -   11  3 +3 
21 821 runs  +5 431  20 781 ✔️ +5 170  1 037 💤 +258  3 +3 

For more details on these failures, see this check.

Results for commit 380a1cc. ± Comparison against base commit 2ab4438.

♻️ This comment has been updated with latest results.

Copy link
Member

@mrocklin mrocklin left a comment

Choose a reason for hiding this comment

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

A few comments. Nothing blocking. They're mostly questions or about general alignment.

@@ -196,21 +195,26 @@ def _to_dict_no_nest(self, *, exclude: "Container[str]" = ()) -> dict:

class MemoryState:
"""Memory readings on a worker or on the whole cluster.
See :doc:`worker-memory`.
Copy link
Member

Choose a reason for hiding this comment

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

Historically we've kept a newline between the title line of a docstring and the body. Thoughts on this? Any objection to continuing with it?

I don't care so much about this particular instance (please don't block on a comment this small), but more broadly I'd love to align on this if it's easy.

https://docs.dask.org/en/stable/develop.html#docstrings


This worker's unique key. This can be its connected address
(such as ``'tcp://127.0.0.1:8891'``) or an alias (such as ``'alice'``).
"""A simple object holding information about a worker."""
Copy link
Member

Choose a reason for hiding this comment

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

Hrm, we're losing most of the docstring here, which I'm a little sad about (although not too sad). I guess the reason not to have a solid docstring here is because then we're keeping two copies of the attributes and types around (and honestly we're probably going to struggle to do even that). I guess that this makes sense.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The Sphinx documentation is still fully generated for the attributes:
https://distributed--6132.org.readthedocs.build/en/6132/scheduling-state.html#worker-state

I found many examples of the docstring falling out of sync with the attributes - I find keeping the documentation of the attribute together with its annotation much more robust. It also lets you spot on the fly the undocumented ones.


@property
def has_what(self) -> "Set[TaskState]":
def has_what(self) -> Set[TaskState]:
Copy link
Member

Choose a reason for hiding this comment

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

It's nice to drop the strings

@@ -1704,7 +1719,7 @@ def _transition(self, key, finish: str, *args, **kwargs):

finish2 = ts._state
# FIXME downcast antipattern
scheduler = pep484_cast(Scheduler, self)
scheduler = cast(Scheduler, self)
Copy link
Member

Choose a reason for hiding this comment

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

I'm curious why this is necessary

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

transition_log and validate are attributes/methods of Scheduler, which are invoked from methods of SchedulerState which is a parent class.

Copy link
Member

Choose a reason for hiding this comment

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

Now that we're no longer doing Cythonization, we should merge these two. Presumably this goes away then 🎉

@crusaderky
Copy link
Collaborator Author

crusaderky commented Apr 15, 2022

Historically we've kept a newline between the title line of a docstring and the body. Thoughts on this?

No problem, fixed

@crusaderky crusaderky merged commit 8931939 into dask:main Apr 19, 2022
@crusaderky crusaderky deleted the scheduler_annotations branch April 19, 2022 08:30
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