Skip to content

Add mild typing to common utils functions#8848

Merged
crusaderky merged 7 commits intodask:mainfrom
mrocklin:utils-type
Mar 31, 2022
Merged

Add mild typing to common utils functions#8848
crusaderky merged 7 commits intodask:mainfrom
mrocklin:utils-type

Conversation

@mrocklin
Copy link
Copy Markdown
Member

I ran into this for parse_timedelta elsewhere.
These functions often change types of things and are commonly used.

I don't want to get into deep typing here (I'll leave that for others)
but a little bit here seemed like it might have unambiguously positive
impact.

I ran into this for parse_timedelta elsewhere.
These functions often change types of things and are commonly used.

I don't want to get into deep typing here (I'll leave that for others)
but a little bit here seemed like it might have unambiguously positive
impact.
Copy link
Copy Markdown
Collaborator

@ian-r-rose ian-r-rose left a comment

Choose a reason for hiding this comment

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

Cool

Comment thread dask/utils.py Outdated
Comment thread dask/utils.py Outdated
Comment thread dask/utils.py Outdated


def parse_timedelta(s, default="seconds"):
def parse_timedelta(s, default="seconds") -> float:
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Suggested change
def parse_timedelta(s, default="seconds") -> float:
def parse_timedelta(s: float | timedelta | str | None, default="seconds") -> float | None:

I'm not sure why there is a None code path here, it doesn't look very useful to me, and type checkers should rightfully complain that this function might return None when people try to us the result as a float.

Ideally we would (a) remove the None option, or (b) if it is important somewhere, include an overload:

@overload
def parse_timedelta(s: None) -> None
    ...

@overload
def parse_timedelta(s: str | float | timedelta) -> float
    ....

def parse_timedelta(s: str | float | timedelta | None) -> float | None
   # implementation

Comment thread dask/utils.py Outdated
Comment thread dask/utils.py Outdated
Comment thread dask/utils.py Outdated
Comment thread dask/utils.py Outdated
Comment thread dask/utils.py Outdated
@mrocklin
Copy link
Copy Markdown
Member Author

Look folks, I'm just doing the minimal thing here. I don't want this to distract people. This has already cost enough time that I regret the PR.

I'm going to put just enough work in so that this isn't wrong and that's it. I'm not focusing on this right now. I'm focusing on getting shuffling in a good state. I apologize for starting this PR.

@mrocklin
Copy link
Copy Markdown
Member Author

If this is good, awesome, let's merge. If there is something broken / damaging then I'll fix it. Let's raise an issue to improve this module in the future (I think that it's one of the higher impact modules for typing) and then prioritize it accordingly.

@mrocklin
Copy link
Copy Markdown
Member Author

Looking back over my PRs I saw this. I'm abandoning this now. If someone wants to pick it up that would be grand. I think that it's good to go, but I'll let others make that determination. Happy to close otherwise.

crusaderky and others added 3 commits March 30, 2022 21:58
@crusaderky
Copy link
Copy Markdown
Collaborator

I'm trying to push to this PR but I get permissions error. @mrocklin is the "Allow edits and access to secrets by maintainers" checkbox ticked?

Comment thread dask/utils.py Outdated
@crusaderky crusaderky self-assigned this Mar 30, 2022
@crusaderky crusaderky merged commit 261bf17 into dask:main Mar 31, 2022
@crusaderky
Copy link
Copy Markdown
Collaborator

Can't push, will open a new PR

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