From 0685d629f86ef27e4b68947f63cb53f2e750d3a7 Mon Sep 17 00:00:00 2001 From: Anil Khatri Date: Tue, 22 Oct 2019 21:32:58 +0530 Subject: fixed classmethod argument PYL-C0202 --- git/refs/log.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'git/refs/log.py') diff --git a/git/refs/log.py b/git/refs/log.py index e8c2d7ad..8d557902 100644 --- a/git/refs/log.py +++ b/git/refs/log.py @@ -84,7 +84,7 @@ class RefLogEntry(tuple): return self[4] @classmethod - def new(self, oldhexsha, newhexsha, actor, time, tz_offset, message): + def new(cls, oldhexsha, newhexsha, actor, time, tz_offset, message): """:return: New instance of a RefLogEntry""" if not isinstance(actor, Actor): raise ValueError("Need actor instance, got %s" % actor) -- cgit v1.2.1 From 5eb8289e80c8b9fe48456e769e0421b7f9972af3 Mon Sep 17 00:00:00 2001 From: Anil Khatri Date: Wed, 23 Oct 2019 23:06:48 +0530 Subject: fix Loop variable used outside the loop --- git/refs/log.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'git/refs/log.py') diff --git a/git/refs/log.py b/git/refs/log.py index 8d557902..01673ae0 100644 --- a/git/refs/log.py +++ b/git/refs/log.py @@ -228,7 +228,7 @@ class RefLog(list, Serializable): # END abort on eof # END handle runup - if i != index or not line: + if i != index or not line: # skipcq:PYL-W0631 raise IndexError # END handle exception -- cgit v1.2.1 From 597fb586347bea58403c0d04ece26de5b6d74423 Mon Sep 17 00:00:00 2001 From: Anil Khatri Date: Wed, 23 Oct 2019 23:12:14 +0530 Subject: fix File opened without the with statement --- git/refs/log.py | 35 ++++++++++++++++++----------------- 1 file changed, 18 insertions(+), 17 deletions(-) (limited to 'git/refs/log.py') diff --git a/git/refs/log.py b/git/refs/log.py index 01673ae0..bc6d4486 100644 --- a/git/refs/log.py +++ b/git/refs/log.py @@ -217,23 +217,24 @@ class RefLog(list, Serializable): the index is negative """ fp = open(filepath, 'rb') - if index < 0: - return RefLogEntry.from_line(fp.readlines()[index].strip()) - else: - # read until index is reached - for i in xrange(index + 1): - line = fp.readline() - if not line: - break - # END abort on eof - # END handle runup - - if i != index or not line: # skipcq:PYL-W0631 - raise IndexError - # END handle exception - - return RefLogEntry.from_line(line.strip()) - # END handle index + with open(filepath, 'rb') as fp: + if index < 0: + return RefLogEntry.from_line(fp.readlines()[index].strip()) + else: + # read until index is reached + for i in xrange(index + 1): + line = fp.readline() + if not line: + break + # END abort on eof + # END handle runup + + if i != index or not line: # skipcq:PYL-W0631 + raise IndexError + # END handle exception + + return RefLogEntry.from_line(line.strip()) + # END handle index def to_file(self, filepath): """Write the contents of the reflog instance to a file at the given filepath. -- cgit v1.2.1 From 1dc46d735003df8ff928974cb07545f69f8ea411 Mon Sep 17 00:00:00 2001 From: Anil Khatri Date: Wed, 23 Oct 2019 23:50:31 +0530 Subject: resolved all minor issues arised by last fix patch --- git/refs/log.py | 45 ++++++++++++++++++++++----------------------- 1 file changed, 22 insertions(+), 23 deletions(-) (limited to 'git/refs/log.py') diff --git a/git/refs/log.py b/git/refs/log.py index bc6d4486..74115145 100644 --- a/git/refs/log.py +++ b/git/refs/log.py @@ -46,13 +46,13 @@ class RefLogEntry(tuple): def format(self): """:return: a string suitable to be placed in a reflog file""" act = self.actor - time = self.time + time_ = self.time_ return u"{} {} {} <{}> {!s} {}\t{}\n".format(self.oldhexsha, self.newhexsha, act.name, act.email, - time[0], - altz_to_utctz_str(time[1]), + time_[0], + altz_to_utctz_str(time_[1]), self.message) @property @@ -71,7 +71,7 @@ class RefLogEntry(tuple): return self[2] @property - def time(self): + def time_(self): """time as tuple: * [0] = int(time) @@ -84,12 +84,12 @@ class RefLogEntry(tuple): return self[4] @classmethod - def new(cls, oldhexsha, newhexsha, actor, time, tz_offset, message): + def new(cls, oldhexsha, newhexsha, actor, time_, tz_offset, message): """:return: New instance of a RefLogEntry""" if not isinstance(actor, Actor): raise ValueError("Need actor instance, got %s" % actor) # END check types - return RefLogEntry((oldhexsha, newhexsha, actor, (time, tz_offset), message)) + return RefLogEntry((oldhexsha, newhexsha, actor, (time_, tz_offset), message)) @classmethod def from_line(cls, line): @@ -121,9 +121,9 @@ class RefLogEntry(tuple): # END handle missing end brace actor = Actor._from_string(info[82:email_end + 1]) - time, tz_offset = parse_date(info[email_end + 2:]) + time_, tz_offset = parse_date(info[email_end + 2:]) - return RefLogEntry((oldhexsha, newhexsha, actor, (time, tz_offset), msg)) + return RefLogEntry((oldhexsha, newhexsha, actor, (time_, tz_offset), msg)) class RefLog(list, Serializable): @@ -220,21 +220,20 @@ class RefLog(list, Serializable): with open(filepath, 'rb') as fp: if index < 0: return RefLogEntry.from_line(fp.readlines()[index].strip()) - else: - # read until index is reached - for i in xrange(index + 1): - line = fp.readline() - if not line: - break - # END abort on eof - # END handle runup - - if i != index or not line: # skipcq:PYL-W0631 - raise IndexError - # END handle exception - - return RefLogEntry.from_line(line.strip()) - # END handle index + # read until index is reached + for i in xrange(index + 1): + line = fp.readline() + if not line: + break + # END abort on eof + # END handle runup + + if i != index or not line: # skipcq:PYL-W0631 + raise IndexError + # END handle exception + + return RefLogEntry.from_line(line.strip()) + # END handle index def to_file(self, filepath): """Write the contents of the reflog instance to a file at the given filepath. -- cgit v1.2.1 From 4dda3cbbd15e7a415c1cbd33f85d7d6d0e3a307a Mon Sep 17 00:00:00 2001 From: Anil Khatri Date: Thu, 24 Oct 2019 21:17:54 +0530 Subject: silance Re-defined variable from outer scope --- git/refs/log.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) (limited to 'git/refs/log.py') diff --git a/git/refs/log.py b/git/refs/log.py index 74115145..243287ad 100644 --- a/git/refs/log.py +++ b/git/refs/log.py @@ -46,13 +46,13 @@ class RefLogEntry(tuple): def format(self): """:return: a string suitable to be placed in a reflog file""" act = self.actor - time_ = self.time_ + time = self.time return u"{} {} {} <{}> {!s} {}\t{}\n".format(self.oldhexsha, self.newhexsha, act.name, act.email, - time_[0], - altz_to_utctz_str(time_[1]), + time[0], + altz_to_utctz_str(time[1]), self.message) @property @@ -71,7 +71,7 @@ class RefLogEntry(tuple): return self[2] @property - def time_(self): + def time(self): """time as tuple: * [0] = int(time) @@ -83,14 +83,16 @@ class RefLogEntry(tuple): """Message describing the operation that acted on the reference""" return self[4] + # skipcq: PYL-W0621 @classmethod - def new(cls, oldhexsha, newhexsha, actor, time_, tz_offset, message): + def new(cls, oldhexsha, newhexsha, actor, time, tz_offset, message): """:return: New instance of a RefLogEntry""" if not isinstance(actor, Actor): raise ValueError("Need actor instance, got %s" % actor) # END check types - return RefLogEntry((oldhexsha, newhexsha, actor, (time_, tz_offset), message)) + return RefLogEntry((oldhexsha, newhexsha, actor, (time, tz_offset), message)) + # skipcq: PYL-W0621 @classmethod def from_line(cls, line): """:return: New RefLogEntry instance from the given revlog line. @@ -121,9 +123,9 @@ class RefLogEntry(tuple): # END handle missing end brace actor = Actor._from_string(info[82:email_end + 1]) - time_, tz_offset = parse_date(info[email_end + 2:]) + time, tz_offset = parse_date(info[email_end + 2:]) - return RefLogEntry((oldhexsha, newhexsha, actor, (time_, tz_offset), msg)) + return RefLogEntry((oldhexsha, newhexsha, actor, (time, tz_offset), msg)) class RefLog(list, Serializable): -- cgit v1.2.1 From 225529c8baaa6ee65b1b23fc1d79b99bf49ebfb1 Mon Sep 17 00:00:00 2001 From: Anil Khatri Date: Thu, 24 Oct 2019 21:22:53 +0530 Subject: silence PYL-W0621 --- git/refs/log.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'git/refs/log.py') diff --git a/git/refs/log.py b/git/refs/log.py index 243287ad..ab5d75a3 100644 --- a/git/refs/log.py +++ b/git/refs/log.py @@ -83,16 +83,14 @@ class RefLogEntry(tuple): """Message describing the operation that acted on the reference""" return self[4] - # skipcq: PYL-W0621 @classmethod - def new(cls, oldhexsha, newhexsha, actor, time, tz_offset, message): + def new(cls, oldhexsha, newhexsha, actor, time, tz_offset, message): # skipcq: PYL-W0621 """:return: New instance of a RefLogEntry""" if not isinstance(actor, Actor): raise ValueError("Need actor instance, got %s" % actor) # END check types return RefLogEntry((oldhexsha, newhexsha, actor, (time, tz_offset), message)) - # skipcq: PYL-W0621 @classmethod def from_line(cls, line): """:return: New RefLogEntry instance from the given revlog line. @@ -123,7 +121,7 @@ class RefLogEntry(tuple): # END handle missing end brace actor = Actor._from_string(info[82:email_end + 1]) - time, tz_offset = parse_date(info[email_end + 2:]) + time, tz_offset = parse_date(info[email_end + 2:]) # skipcq: PYL-W0621 return RefLogEntry((oldhexsha, newhexsha, actor, (time, tz_offset), msg)) -- cgit v1.2.1 From 9932e647aaaaf6edd3a407b75edd08a96132ef5c Mon Sep 17 00:00:00 2001 From: Anil Khatri Date: Mon, 28 Oct 2019 15:34:09 +0530 Subject: removed extra line as per code review --- git/refs/log.py | 1 - 1 file changed, 1 deletion(-) (limited to 'git/refs/log.py') diff --git a/git/refs/log.py b/git/refs/log.py index ab5d75a3..432232ac 100644 --- a/git/refs/log.py +++ b/git/refs/log.py @@ -216,7 +216,6 @@ class RefLog(list, Serializable): all other lines. Nonetheless, the whole file has to be read if the index is negative """ - fp = open(filepath, 'rb') with open(filepath, 'rb') as fp: if index < 0: return RefLogEntry.from_line(fp.readlines()[index].strip()) -- cgit v1.2.1