Skip to content

Commit

Permalink
linting lines size and count
Browse files Browse the repository at this point in the history
- removed print function
- inlined docstring to reduce lines
- disbaled pylint in test compatibility
  • Loading branch information
rsb-23 committed Jan 15, 2025
1 parent ea2e7e8 commit ef757b5
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 42 deletions.
3 changes: 1 addition & 2 deletions .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -31,7 +31,6 @@ disable=
consider-using-f-string,
import-outside-toplevel,
invalid-name,
line-too-long,
missing-docstring,
unidiomatic-typecheck,
# R
Expand Down
11 changes: 9 additions & 2 deletions tests/test_behaviors.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,20 @@ def test_multi_date_behavior():
"""
parse_r_date = vobject.icalendar.MultiDateBehavior.transformToNative

expected = "<RDATE{'VALUE': ['DATE']}[datetime.date(1997, 3, 4), datetime.date(1997, 5, 4), datetime.date(1997, 7, 4), datetime.date(1997, 9, 4)]>"
expected = (
"<RDATE{'VALUE': ['DATE']}[datetime.date(1997, 3, 4), datetime.date(1997, 5, 4), "
"datetime.date(1997, 7, 4), datetime.date(1997, 9, 4)]>"
)
result = str(
parse_r_date(vobject.base.textLineToContentLine("RDATE;VALUE=DATE:19970304,19970504,19970704,19970904"))
)
assert result == expected

expected = "<RDATE{'VALUE': ['PERIOD']}[(datetime.datetime(1996, 4, 3, 2, 0, tzinfo=tzutc()), datetime.datetime(1996, 4, 3, 4, 0, tzinfo=tzutc())), (datetime.datetime(1996, 4, 4, 1, 0, tzinfo=tzutc()), datetime.timedelta(seconds=10800))]>"
expected = (
"<RDATE{'VALUE': ['PERIOD']}[(datetime.datetime(1996, 4, 3, 2, 0, tzinfo=tzutc()), "
"datetime.datetime(1996, 4, 3, 4, 0, tzinfo=tzutc())), "
"(datetime.datetime(1996, 4, 4, 1, 0, tzinfo=tzutc()), datetime.timedelta(seconds=10800))]>"
)
result = str(
parse_r_date(
vobject.base.textLineToContentLine(
Expand Down
1 change: 1 addition & 0 deletions tests/test_compatibility.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# pylint: disable=c0301,c0302
import vobject


Expand Down
47 changes: 11 additions & 36 deletions vobject/base.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
"""vobject module for reading vCard and vCalendar files."""

from __future__ import print_function

import codecs
import copy
import io
Expand All @@ -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):
Expand All @@ -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 ---------------------------------
Expand Down Expand Up @@ -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()
Expand All @@ -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():
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions vobject/icalendar.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit ef757b5

Please sign in to comment.