Skip to content

Commit af32039

Browse files
committed
Fix mismatches between base and derived class method signatures.
This clears a bunch of warnings from PyCharm.
1 parent 2094c71 commit af32039

File tree

2 files changed

+57
-64
lines changed

2 files changed

+57
-64
lines changed

vobject/icalendar.py

Lines changed: 44 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -722,8 +722,8 @@ class RecurringBehavior(VCalendarComponentBehavior):
722722

723723
hasNative = True
724724

725-
@staticmethod
726-
def transformToNative(obj):
725+
@classmethod
726+
def transformToNative(cls, obj):
727727
"""
728728
Turn a recurring Component into a RecurringComponent.
729729
"""
@@ -732,15 +732,15 @@ def transformToNative(obj):
732732
obj.isNative = True
733733
return obj
734734

735-
@staticmethod
736-
def transformFromNative(obj):
735+
@classmethod
736+
def transformFromNative(cls, obj):
737737
if obj.isNative:
738738
object.__setattr__(obj, "__class__", Component)
739739
obj.isNative = False
740740
return obj
741741

742-
@staticmethod
743-
def generateImplicitParameters(obj):
742+
@classmethod
743+
def generateImplicitParameters(cls, obj):
744744
"""
745745
Generate a UID and DTSTAMP if one does not exist.
746746
@@ -765,8 +765,8 @@ class DateTimeBehavior(behavior.Behavior):
765765

766766
hasNative = True
767767

768-
@staticmethod
769-
def transformToNative(obj):
768+
@classmethod
769+
def transformToNative(cls, obj):
770770
"""
771771
Turn obj.value into a datetime.
772772
@@ -825,8 +825,8 @@ class DateOrDateTimeBehavior(behavior.Behavior):
825825

826826
hasNative = True
827827

828-
@staticmethod
829-
def transformToNative(obj):
828+
@classmethod
829+
def transformToNative(cls, obj):
830830
"""
831831
Turn obj.value into a date or datetime.
832832
"""
@@ -843,8 +843,8 @@ def transformToNative(obj):
843843
del obj.tzid_param
844844
return obj
845845

846-
@staticmethod
847-
def transformFromNative(obj):
846+
@classmethod
847+
def transformFromNative(cls, obj):
848848
"""
849849
Replace the date or datetime in obj.value with an ISO 8601 string.
850850
"""
@@ -865,8 +865,8 @@ class MultiDateBehavior(behavior.Behavior):
865865

866866
hasNative = True
867867

868-
@staticmethod
869-
def transformToNative(obj):
868+
@classmethod
869+
def transformToNative(cls, obj):
870870
"""
871871
Turn obj.value into a list of dates, datetimes, or
872872
(datetime, timedelta) tuples.
@@ -888,8 +888,8 @@ def transformToNative(obj):
888888
obj.value = [stringToPeriod(x, tzinfo) for x in valTexts]
889889
return obj
890890

891-
@staticmethod
892-
def transformFromNative(obj):
891+
@classmethod
892+
def transformFromNative(cls, obj):
893893
"""
894894
Replace the date, datetime or period tuples in obj.value with
895895
appropriate strings.
@@ -1104,31 +1104,31 @@ class VTimezone(VCalendarComponentBehavior):
11041104
}
11051105

11061106
@classmethod
1107-
def validate(cls, obj, raiseException, *args):
1107+
def validate(cls, obj, raiseException=False, complainUnrecognized=False):
11081108
if not hasattr(obj, "tzid") or obj.tzid.value is None:
11091109
if raiseException:
11101110
m = "VTIMEZONE components must contain a valid TZID"
11111111
raise ValidateError(m)
11121112
return False
11131113
if "standard" in obj.contents or "daylight" in obj.contents:
1114-
return super(VTimezone, cls).validate(obj, raiseException, *args)
1114+
return super(VTimezone, cls).validate(obj, raiseException, complainUnrecognized)
11151115
else:
11161116
if raiseException:
11171117
m = "VTIMEZONE components must contain a STANDARD or a DAYLIGHT\
11181118
component"
11191119
raise ValidateError(m)
11201120
return False
11211121

1122-
@staticmethod
1123-
def transformToNative(obj):
1122+
@classmethod
1123+
def transformToNative(cls, obj):
11241124
if not obj.isNative:
11251125
object.__setattr__(obj, "__class__", TimezoneComponent)
11261126
obj.isNative = True
11271127
obj.registerTzinfo(obj.tzinfo)
11281128
return obj
11291129

1130-
@staticmethod
1131-
def transformFromNative(obj):
1130+
@classmethod
1131+
def transformFromNative(cls, obj):
11321132
return obj
11331133

11341134

@@ -1206,15 +1206,15 @@ class VEvent(RecurringBehavior):
12061206
}
12071207

12081208
@classmethod
1209-
def validate(cls, obj, raiseException, *args):
1209+
def validate(cls, obj, raiseException=False, complainUnrecognized=False):
12101210
if "dtend" in obj.contents and "duration" in obj.contents:
12111211
if raiseException:
12121212
m = "VEVENT components cannot contain both DTEND and DURATION\
12131213
components"
12141214
raise ValidateError(m)
12151215
return False
12161216
else:
1217-
return super(VEvent, cls).validate(obj, raiseException, *args)
1217+
return super(VEvent, cls).validate(obj, raiseException, complainUnrecognized)
12181218

12191219

12201220
registerBehavior(VEvent)
@@ -1266,15 +1266,15 @@ class VTodo(RecurringBehavior):
12661266
}
12671267

12681268
@classmethod
1269-
def validate(cls, obj, raiseException, *args):
1269+
def validate(cls, obj, raiseException=False, complainUnrecognized=False):
12701270
if "due" in obj.contents and "duration" in obj.contents:
12711271
if raiseException:
12721272
m = "VTODO components cannot contain both DUE and DURATION\
12731273
components"
12741274
raise ValidateError(m)
12751275
return False
12761276
else:
1277-
return super(VTodo, cls).validate(obj, raiseException, *args)
1277+
return super(VTodo, cls).validate(obj, raiseException, complainUnrecognized)
12781278

12791279

12801280
registerBehavior(VTodo)
@@ -1362,8 +1362,8 @@ class VAlarm(VCalendarComponentBehavior):
13621362
"DESCRIPTION": (0, 1, None),
13631363
}
13641364

1365-
@staticmethod
1366-
def generateImplicitParameters(obj):
1365+
@classmethod
1366+
def generateImplicitParameters(cls, obj):
13671367
"""
13681368
Create default ACTION and TRIGGER if they're not set.
13691369
"""
@@ -1377,7 +1377,7 @@ def generateImplicitParameters(obj):
13771377
obj.add("trigger").value = datetime.timedelta(0)
13781378

13791379
@classmethod
1380-
def validate(cls, obj, raiseException, *args):
1380+
def validate(cls, obj, raiseException=False, complainUnrecognized=False):
13811381
"""
13821382
# TODO
13831383
if obj.contents.has_key('dtend') and obj.contents.has_key('duration'):
@@ -1387,7 +1387,7 @@ def validate(cls, obj, raiseException, *args):
13871387
raise ValidateError(m)
13881388
return False
13891389
else:
1390-
return super(VEvent, cls).validate(obj, raiseException, *args)
1390+
return super(VEvent, cls).validate(obj, raiseException, complainUnrecognized)
13911391
"""
13921392
return True
13931393

@@ -1425,14 +1425,14 @@ class VAvailability(VCalendarComponentBehavior):
14251425
}
14261426

14271427
@classmethod
1428-
def validate(cls, obj, raiseException, *args):
1428+
def validate(cls, obj, raiseException=False, complainUnrecognized=False):
14291429
if "dtend" in obj.contents and "duration" in obj.contents:
14301430
if raiseException:
14311431
m = "VAVAILABILITY components cannot contain both DTEND and DURATION components"
14321432
raise ValidateError(m)
14331433
return False
14341434
else:
1435-
return super(VAvailability, cls).validate(obj, raiseException, *args)
1435+
return super(VAvailability, cls).validate(obj, raiseException, complainUnrecognized)
14361436

14371437

14381438
registerBehavior(VAvailability)
@@ -1465,7 +1465,7 @@ class Available(RecurringBehavior):
14651465
}
14661466

14671467
@classmethod
1468-
def validate(cls, obj, raiseException, *args):
1468+
def validate(cls, obj, raiseException=False, complainUnrecognized=False):
14691469
has_dtend = "dtend" in obj.contents
14701470
has_duration = "duration" in obj.contents
14711471
if has_dtend and has_duration:
@@ -1481,7 +1481,7 @@ def validate(cls, obj, raiseException, *args):
14811481
raise ValidateError(m)
14821482
return False
14831483
else:
1484-
return super(Available, cls).validate(obj, raiseException, *args)
1484+
return super(Available, cls).validate(obj, raiseException, complainUnrecognized)
14851485

14861486

14871487
registerBehavior(Available)
@@ -1495,8 +1495,8 @@ class Duration(behavior.Behavior):
14951495
name = "DURATION"
14961496
hasNative = True
14971497

1498-
@staticmethod
1499-
def transformToNative(obj):
1498+
@classmethod
1499+
def transformToNative(cls, obj):
15001500
"""
15011501
Turn obj.value into a datetime.timedelta.
15021502
"""
@@ -1515,8 +1515,8 @@ def transformToNative(obj):
15151515
else:
15161516
raise ParseError("DURATION must have a single duration string.")
15171517

1518-
@staticmethod
1519-
def transformFromNative(obj):
1518+
@classmethod
1519+
def transformFromNative(cls, obj):
15201520
"""
15211521
Replace the datetime.timedelta in obj.value with an RFC2445 string.
15221522
"""
@@ -1540,8 +1540,8 @@ class Trigger(behavior.Behavior):
15401540
hasNative = True
15411541
forceUTC = True
15421542

1543-
@staticmethod
1544-
def transformToNative(obj):
1543+
@classmethod
1544+
def transformToNative(cls, obj):
15451545
"""
15461546
Turn obj.value into a timedelta or datetime.
15471547
"""
@@ -1576,8 +1576,8 @@ def transformToNative(obj):
15761576
else:
15771577
raise ParseError("VALUE must be DURATION or DATE-TIME")
15781578

1579-
@staticmethod
1580-
def transformFromNative(obj):
1579+
@classmethod
1580+
def transformFromNative(cls, obj):
15811581
if type(obj.value) is datetime.datetime:
15821582
obj.value_param = "DATE-TIME"
15831583
return UTCDateTimeBehavior.transformFromNative(obj)
@@ -1597,8 +1597,8 @@ class PeriodBehavior(behavior.Behavior):
15971597

15981598
hasNative = True
15991599

1600-
@staticmethod
1601-
def transformToNative(obj):
1600+
@classmethod
1601+
def transformToNative(cls, obj):
16021602
"""
16031603
Convert comma separated periods into tuples.
16041604
"""
@@ -2165,10 +2165,3 @@ def dt_test(dt):
21652165
if t1 != t2 or not dt_test(t1):
21662166
return False
21672167
return True
2168-
2169-
2170-
# ------------------- Testing and running functions ----------------------------
2171-
if __name__ == "__main__":
2172-
import tests
2173-
2174-
tests._test()

vobject/vcard.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ def valueRepr(cls, line):
237237
return f" (BINARY PHOTO DATA at 0x{id(line.value)}) "
238238

239239
@classmethod
240-
def serialize(cls, obj, buf, lineLength, validate, *args, **kwargs):
240+
def serialize(cls, obj, buf, lineLength, validate=True, *args, **kwargs):
241241
"""
242242
Apple's Address Book is *really* weird with images, it expects
243243
base64 data to have very specific whitespace. It seems Address Book
@@ -300,8 +300,8 @@ class NameBehavior(VCardBehavior):
300300

301301
hasNative = True
302302

303-
@staticmethod
304-
def transformToNative(obj):
303+
@classmethod
304+
def transformToNative(cls, obj):
305305
"""
306306
Turn obj.value into a Name.
307307
"""
@@ -311,8 +311,8 @@ def transformToNative(obj):
311311
obj.value = Name(**dict(zip(NAME_ORDER, splitFields(obj.value))))
312312
return obj
313313

314-
@staticmethod
315-
def transformFromNative(obj):
314+
@classmethod
315+
def transformFromNative(cls, obj):
316316
"""
317317
Replace the Name in obj.value with a string.
318318
"""
@@ -331,8 +331,8 @@ class AddressBehavior(VCardBehavior):
331331

332332
hasNative = True
333333

334-
@staticmethod
335-
def transformToNative(obj):
334+
@classmethod
335+
def transformToNative(cls, obj):
336336
"""
337337
Turn obj.value into an Address.
338338
"""
@@ -342,8 +342,8 @@ def transformToNative(obj):
342342
obj.value = Address(**dict(zip(ADDRESS_ORDER, splitFields(obj.value))))
343343
return obj
344344

345-
@staticmethod
346-
def transformFromNative(obj):
345+
@classmethod
346+
def transformFromNative(cls, obj):
347347
"""
348348
Replace the Address in obj.value with a string.
349349
"""
@@ -362,8 +362,8 @@ class OrgBehavior(VCardBehavior):
362362

363363
hasNative = True
364364

365-
@staticmethod
366-
def transformToNative(obj):
365+
@classmethod
366+
def transformToNative(cls, obj):
367367
"""
368368
Turn obj.value into a list.
369369
"""
@@ -373,8 +373,8 @@ def transformToNative(obj):
373373
obj.value = splitFields(obj.value)
374374
return obj
375375

376-
@staticmethod
377-
def transformFromNative(obj):
376+
@classmethod
377+
def transformFromNative(cls, obj):
378378
"""
379379
Replace the list in obj.value with a string.
380380
"""

0 commit comments

Comments
 (0)