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

Type annotations fixed #200

Merged
merged 3 commits into from
Jan 10, 2021
Merged

Type annotations fixed #200

merged 3 commits into from
Jan 10, 2021

Conversation

CCCodes
Copy link

@CCCodes CCCodes commented Dec 17, 2020

Fixes #185.

Changes proposed in this PR:
Add type annotations for

  • jobManager.py
  • jobQueue.py
  • tangoObjects.py
  • worker.py
  • tango.py
  • preallocator.py

Some type annotations are best guesses because it was hard to determine exactly what types were acceptable. I ran all unittests on it and got the same results with / and without the annotations, so there were no problems in those cases.

@fanpu
Copy link
Contributor

fanpu commented Dec 21, 2020

Hi @CCCodes, thank you for updating the PR based on my previous comments! Apologies for the delay in response, I'll be reviewing it now

tango.py Outdated
@@ -209,7 +209,7 @@ def getInfo(self):
#
# Helper functions
#
def resetTango(self, vmms):
def resetTango(self, vmms: list) -> None:
Copy link
Contributor

@fanpu fanpu Dec 21, 2020

Choose a reason for hiding this comment

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

list should be List[<some type>] instead, and can be imported with from typing import List

Copy link
Contributor

@fanpu fanpu left a comment

Choose a reason for hiding this comment

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

Great job overall and thanks so much for your contributions! There are some compound types and custom datatypes whose annotations are wrong but it's also partially the fault of the lack of a CI pipeline in Tango which means that you won't really be able to check if they are actually working. Could you address the comments, and once those are done it should be good to go!

@@ -313,7 +315,7 @@ def makeDead(self, id, reason):
self.log.debug("makeDead| Released lock to job queue.")
return status

def getInfo(self):
def getInfo(self) -> dict:
Copy link
Contributor

Choose a reason for hiding this comment

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

Dict should be capitalized and contain the type mapping, see https://docs.python.org/3/library/typing.html#typing.Dict

@@ -353,7 +355,7 @@ def getNextPendingJob(self):
self.log.debug("getNextPendingJob| Released lock to job queue.")
return job

def reuseVM(self, job):
def reuseVM(self, job: TangoJob) -> Optional['vm']:
Copy link
Contributor

Choose a reason for hiding this comment

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

'vm' is probably not a valid type

tangoObjects.py Outdated
from queue import Queue
from config import Config

redisConnection = None


def getRedisConnection():
def getRedisConnection() -> redis.StrictRedis:
Copy link
Contributor

Choose a reason for hiding this comment

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

Figuring out the type of this is tricky, it's actually redis.client.Redis. You can do it by installing mypy, creating a test python file (say test.py), adding the following stub:

import redis
reveal_type(redis.StrictRedis(host='localhost', port=6379, db=0))

reveal_type is a feature from mypy that has an example here: https://mypy.readthedocs.io/en/stable/cheat_sheet_py3.html#when-you-re-puzzled-or-when-things-are-complicated

tangoObjects.py Outdated
self.__db.delete(self.key)

# This is an abstract class that decides on
# if we should initiate a TangoRemoteDictionary or TangoNativeDictionary
# Since there are no abstract classes in Python, we use a simple method
def TangoDictionary(object_name):
def TangoDictionary(object_name) -> 'TangoDictionary':
Copy link
Contributor

Choose a reason for hiding this comment

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

This should be tangoObjects.TangoRemoteDictionary

tangoObjects.py Outdated
keys = map(lambda key : key.decode(), self.r.hkeys(self.hash_name))
return list(keys)

def values(self):
def values(self) -> list:
Copy link
Contributor

Choose a reason for hiding this comment

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

Same comment on list as before

@CCCodes
Copy link
Author

CCCodes commented Dec 26, 2020

Thanks for the feedback, I will work on the changes now!

@CCCodes CCCodes requested a review from fanpu December 27, 2020 03:40
@fanpu fanpu changed the base branch from master to typechecking January 10, 2021 17:52
Copy link
Contributor

@fanpu fanpu 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 making the changes @CCCodes! I looked through the changes again and found a few more issues but I'll be able to take care of them. Merging changes into a temporary branch first in order to fix these issues. Once again thanks for your contributions!

@fanpu fanpu merged commit be3ea1d into autolab:typechecking Jan 10, 2021
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.

Type annotations
2 participants