mirror of
https://github.com/RYDE-WORK/ballistica.git
synced 2026-02-08 16:53:49 +08:00
moved IOAttrs defaults to class level
This commit is contained in:
parent
2f2ae11d4f
commit
06514e913b
@ -72,14 +72,27 @@ class Codec(Enum):
|
|||||||
class IOAttrs:
|
class IOAttrs:
|
||||||
"""For specifying io behavior in annotations."""
|
"""For specifying io behavior in annotations."""
|
||||||
|
|
||||||
|
storagename: Optional[str] = None
|
||||||
|
store_default: bool = True
|
||||||
|
whole_days: bool = False
|
||||||
|
whole_hours: bool = False
|
||||||
|
|
||||||
def __init__(self,
|
def __init__(self,
|
||||||
storagename: str = None,
|
storagename: Optional[str] = storagename,
|
||||||
store_default: bool = True,
|
store_default: bool = store_default,
|
||||||
whole_days: bool = False,
|
whole_days: bool = whole_days,
|
||||||
whole_hours: bool = False):
|
whole_hours: bool = whole_hours):
|
||||||
|
|
||||||
|
# Only store values that differ from class defaults to keep
|
||||||
|
# our instances nice and lean.
|
||||||
|
cls = type(self)
|
||||||
|
if storagename != cls.storagename:
|
||||||
self.storagename = storagename
|
self.storagename = storagename
|
||||||
|
if store_default != cls.store_default:
|
||||||
self.store_default = store_default
|
self.store_default = store_default
|
||||||
|
if whole_days != cls.whole_days:
|
||||||
self.whole_days = whole_days
|
self.whole_days = whole_days
|
||||||
|
if whole_hours != cls.whole_hours:
|
||||||
self.whole_hours = whole_hours
|
self.whole_hours = whole_hours
|
||||||
|
|
||||||
def validate_for_field(self, cls: Type, field: dataclasses.Field) -> None:
|
def validate_for_field(self, cls: Type, field: dataclasses.Field) -> None:
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user