Skip to content

⚡️ Speed up method BashJob.__eq__ by 26% #21

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions pypette/jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def __init__(
:param args: Argument list to run the method with.
:param kwargs: Keyword arguments to run the method with.
"""
assert isroutine(function), 'Python callable expected'
assert isroutine(function), "Python callable expected"
assert isinstance(args, tuple)
assert isinstance(kwargs, dict)

Expand All @@ -70,7 +70,9 @@ def __eq__(self, other: Any) -> bool:
)

def __repr__(self) -> str:
return 'Job(function={}, args={}, kwargs={})'.format(self.name, self.args, self.kwargs)
return "Job(function={}, args={}, kwargs={})".format(
self.name, self.args, self.kwargs
)


class BashJob(JobInterface):
Expand All @@ -81,13 +83,15 @@ def __init__(self, cmd: List[str]):

:param cmd: Bash command to run.
"""
assert isinstance(cmd, list), 'Bash command as list of strings needed'
if not isinstance(cmd, list):
raise TypeError("Bash command as list of strings needed")

super(BashJob, self).__init__(' '.join(cmd))
super().__init__(" ".join(cmd))
self.cmd: List[str] = cmd

def __eq__(self, other: Any) -> bool:
return type(self) == type(other) and self.cmd == other.cmd
# Use isinstance for subclass safety and faster path
return isinstance(other, BashJob) and self.cmd == other.cmd

def __repr__(self) -> str:
return 'BashJob(cmd={})'.format(self.name)
return "BashJob(cmd={})".format(self.name)
Loading