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 core typings #59

Merged
merged 17 commits into from
Dec 16, 2020
Merged

Add core typings #59

merged 17 commits into from
Dec 16, 2020

Conversation

nazywam
Copy link
Member

@nazywam nazywam commented Dec 15, 2020

Closes #53
Closes #60

@nazywam nazywam requested a review from psrok1 December 15, 2020 15:37
karton/core/backend.py Outdated Show resolved Hide resolved
Co-authored-by: Paweł Srokosz <pawel.srokosz@cert.pl>
@psrok1 psrok1 self-assigned this Dec 15, 2020
Copy link
Member

@psrok1 psrok1 left a comment

Choose a reason for hiding this comment

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

I would check if transforming type(x) is str to isinstance(x, str) helps mypy to deduce type assertions. If yes, this should be used to avoid some casts.

karton/core/base.py Show resolved Hide resolved
def last_update(self) -> int:
return max(task.last_update for task in self.tasks)
def last_update(self) -> float:
return max(task.last_update for task in self.tasks if task.last_update)
Copy link
Member

Choose a reason for hiding this comment

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

I would make the last_update non-optional (e.g. initialize with time.time() on construction). If max gets the empty sequence, raises exception ValueError: max() arg is an empty sequence which might be not expected by user.

Copy link
Member Author

Choose a reason for hiding this comment

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

Corrected, although it still could raise that exception if self.tasks is empty

karton/core/task.py Show resolved Hide resolved
karton/core/task.py Outdated Show resolved Hide resolved
karton/core/resource.py Show resolved Hide resolved
karton/core/resource.py Show resolved Hide resolved
karton/core/resource.py Outdated Show resolved Hide resolved
karton/core/resource.py Outdated Show resolved Hide resolved
karton/core/resource.py Outdated Show resolved Hide resolved
karton/core/resource.py Outdated Show resolved Hide resolved
@nazywam nazywam requested a review from psrok1 December 16, 2020 10:27
Copy link
Member

@psrok1 psrok1 left a comment

Choose a reason for hiding this comment

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

Looks ok 👍

@psrok1 psrok1 merged commit 1be3964 into master Dec 16, 2020
@psrok1 psrok1 deleted the update/core-typings branch December 16, 2020 13:06
psrok1 added a commit that referenced this pull request Dec 18, 2020
* Add core typings

* Sort imports

* Format code with black

* Reformat with correct black

* Fix circular import

* Make flake happy

* Make mypy happy

* Update karton/core/backend.py

Co-authored-by: Paweł Srokosz <pawel.srokosz@cert.pl>

* Refactor content in ResourceBase constructor

* Reformat

* Make task.last_update no-noptional

* Split long lines

* More exceptions

* Reformat

* Add system typings

* Check downloaded task

Co-authored-by: Paweł Srokosz <pawel.srokosz@cert.pl>
@psrok1 psrok1 restored the update/core-typings branch December 18, 2020 12:15
@psrok1 psrok1 deleted the update/core-typings branch December 18, 2020 12:15
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.

Optimize get_task_queue to use get_tasks (mget) Complete typing for Karton library
2 participants