From ef757b53d60d00954b49e6bf90e862422ccc95af Mon Sep 17 00:00:00 2001 From: rsb-23 <57601627+rsb-23@users.noreply.github.com> Date: Wed, 15 Jan 2025 14:09:00 +0530 Subject: [PATCH] linting lines size and count - removed print function - inlined docstring to reduce lines - disbaled pylint in test compatibility --- .pylintrc | 3 +-- tests/test_behaviors.py | 11 +++++++-- tests/test_compatibility.py | 1 + vobject/base.py | 47 +++++++++---------------------------- vobject/icalendar.py | 3 +-- 5 files changed, 23 insertions(+), 42 deletions(-) diff --git a/.pylintrc b/.pylintrc index 2af8892..3a99e88 100644 --- a/.pylintrc +++ b/.pylintrc @@ -10,7 +10,7 @@ max-attributes = 9 max-bool-expr = 6 max-branches = 32 max-locals = 31 -max-module-lines = 27989 +max-module-lines = 1200 max-nested-blocks = 6 max-positional-arguments = 8 max-statements = 95 @@ -31,7 +31,6 @@ disable= consider-using-f-string, import-outside-toplevel, invalid-name, - line-too-long, missing-docstring, unidiomatic-typecheck, # R diff --git a/tests/test_behaviors.py b/tests/test_behaviors.py index f85d1b1..61f1d11 100644 --- a/tests/test_behaviors.py +++ b/tests/test_behaviors.py @@ -24,13 +24,20 @@ def test_multi_date_behavior(): """ parse_r_date = vobject.icalendar.MultiDateBehavior.transformToNative - expected = "" + expected = ( + "" + ) result = str( parse_r_date(vobject.base.textLineToContentLine("RDATE;VALUE=DATE:19970304,19970504,19970704,19970904")) ) assert result == expected - expected = "" + expected = ( + "" + ) result = str( parse_r_date( vobject.base.textLineToContentLine( diff --git a/tests/test_compatibility.py b/tests/test_compatibility.py index 9a447d2..66badb4 100644 --- a/tests/test_compatibility.py +++ b/tests/test_compatibility.py @@ -1,3 +1,4 @@ +# pylint: disable=c0301,c0302 import vobject diff --git a/vobject/base.py b/vobject/base.py index 953a9dc..fe7f1ea 100644 --- a/vobject/base.py +++ b/vobject/base.py @@ -1,7 +1,5 @@ """vobject module for reading vCard and vCalendar files.""" -from __future__ import print_function - import codecs import copy import io @@ -18,22 +16,16 @@ def str_(s): - """ - Return string - """ return s def to_unicode(value): """Converts a string argument to a unicode string. - If the argument is already a unicode string, it is returned - unchanged. Otherwise it must be a byte string and is decoded as utf8. + If the argument is already a unicode string, it is returned unchanged. + Otherwise it must be a byte string and is decoded as utf8. """ - if isinstance(value, unicode_type): - return value - - return value.decode("utf-8") + return value if isinstance(value, unicode_type) else value.decode("utf-8") def to_basestring(s): @@ -42,10 +34,7 @@ def to_basestring(s): If the argument is already a byte string, it is returned unchanged. Otherwise it must be a unicode string and is encoded as utf8. """ - if isinstance(s, bytes): - return s - - return s.encode("utf-8") + return s if isinstance(s, bytes) else s.encode("utf-8") # ------------------------------------ Logging --------------------------------- @@ -102,23 +91,15 @@ def copy(self, copyit): self.isNative = copyit.isNative def validate(self, *args, **kwds): - """ - Call the behavior's validate method, or return True. - """ - if self.behavior: - return self.behavior.validate(self, *args, **kwds) - return True + """Call the behavior's validate method, or return True.""" + return self.behavior.validate(self, *args, **kwds) if self.behavior else True def getChildren(self): - """ - Return an iterable containing the contents of the object. - """ + """Return an iterable containing the contents of the object.""" return [] def clearBehavior(self, cascade=True): - """ - Set behavior to None. Do for all descendants if cascading. - """ + """Set behavior to None. Do for all descendants if cascading.""" self.behavior = None if cascade: self.transformChildrenFromNative() @@ -145,9 +126,7 @@ def autoBehavior(self, cascade=False): self.behavior.decode(self) def setBehavior(self, behavior, cascade=True): - """ - Set behavior. If cascade is True, autoBehavior all descendants. - """ + """Set behavior. If cascade is True, autoBehavior all descendants.""" self.behavior = behavior if cascade: for obj in self.getChildren(): @@ -239,8 +218,7 @@ def serialize(self, buf=None, lineLength=75, validate=True, behavior=None, *args def toVName(name, stripNum=0, upper=False): """ - Turn a Python name into an iCalendar style name, - optionally uppercase and with characters stripped off. + Turn a Python name into an iCalendar style name, optionally uppercase and with characters stripped off. """ if upper: name = name.upper() @@ -371,10 +349,7 @@ def __setattr__(self, name, value): which are legal in IANA tokens. """ if name.endswith("_param"): - if type(value) is list: - self.params[toVName(name, 6, True)] = value - else: - self.params[toVName(name, 6, True)] = [value] + self.params[toVName(name, 6, True)] = value if type(value) is list else [value] elif name.endswith("_paramlist"): if type(value) is list: self.params[toVName(name, 10, True)] = value diff --git a/vobject/icalendar.py b/vobject/icalendar.py index 3a090e4..2b30870 100644 --- a/vobject/icalendar.py +++ b/vobject/icalendar.py @@ -1,7 +1,6 @@ +# pylint: disable=c0302 """Definitions and behavior for iCalendar, also known as vCalendar 2.0""" -from __future__ import print_function - import base64 import datetime import io