Skip to content

Commit cc018f9

Browse files
authored
Fix default function values (#306)
* Fix default values * Tooltip
1 parent 9d2cb3b commit cc018f9

File tree

7 files changed

+41
-28
lines changed

7 files changed

+41
-28
lines changed

src/daf/guild.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ async def _on_invite_delete(self, invite: discord.Invite):
306306
"""
307307
raise NotImplementedError
308308

309-
async def update(self, init_options={}, **kwargs):
309+
async def update(self, init_options = None, **kwargs):
310310
"""
311311
.. versionadded:: v2.0
312312
@@ -443,7 +443,7 @@ class GUILD(_BaseGUILD):
443443
@typechecked
444444
def __init__(self,
445445
snowflake: Union[int, discord.Guild],
446-
messages: Optional[List[Union[TextMESSAGE, VoiceMESSAGE]]] = [],
446+
messages: Optional[List[Union[TextMESSAGE, VoiceMESSAGE]]] = None,
447447
logging: Optional[bool] = False,
448448
remove_after: Optional[Union[timedelta, datetime]] = None,
449449
invite_track: Optional[List[str]] = None):
@@ -568,7 +568,7 @@ def generate_invite_log_context(self, member: discord.Member, invite_id: str) ->
568568
}
569569

570570
@misc._async_safe("update_semaphore", 1)
571-
async def update(self, init_options = {}, _init = True, **kwargs):
571+
async def update(self, init_options = None, _init = True, **kwargs):
572572
"""
573573
Used for changing the initialization parameters,
574574
the object was initialized with.
@@ -600,7 +600,7 @@ async def update(self, init_options = {}, _init = True, **kwargs):
600600
if "invite_track" not in kwargs:
601601
kwargs["invite_track"] = list(self.join_count.keys())
602602

603-
if len(init_options) == 0:
603+
if init_options is None:
604604
init_options = {"parent": self.parent}
605605

606606
# Add uninitialized servers
@@ -651,7 +651,7 @@ class USER(_BaseGUILD):
651651
def __init__(
652652
self,
653653
snowflake: Union[int, discord.User],
654-
messages: Optional[List[DirectMESSAGE]] = [],
654+
messages: Optional[List[DirectMESSAGE]] = None,
655655
logging: Optional[bool] = False,
656656
remove_after: Optional[Union[timedelta, datetime]] = None
657657
) -> None:
@@ -689,7 +689,7 @@ async def initialize(self, parent: Any):
689689
)
690690

691691
@misc._async_safe("update_semaphore", 1)
692-
async def update(self, init_options = {}, _init = True, **kwargs):
692+
async def update(self, init_options = None, _init = True, **kwargs):
693693
"""
694694
.. versionadded:: v2.0
695695
@@ -718,7 +718,7 @@ async def update(self, init_options = {}, _init = True, **kwargs):
718718
if "snowflake" not in kwargs:
719719
kwargs["snowflake"] = self.snowflake
720720

721-
if len(init_options) == 0:
721+
if init_options is None:
722722
init_options = {"parent": self.parent}
723723

724724
messages = kwargs.pop("messages", self.messages)
@@ -790,7 +790,7 @@ class AutoGUILD:
790790
logging: Optional[bool] = False
791791
Set to True if you want the guilds generated to log
792792
sent messages.
793-
interval: Optional[timedelta] = timedelta(minutes=10)
793+
interval: Optional[timedelta] = timedelta(minutes=1)
794794
Interval at which to scan for new guilds
795795
auto_join: Optional[web.GuildDISCOVERY] = None
796796
.. versionadded:: v2.5
@@ -824,7 +824,7 @@ def __init__(self,
824824
include_pattern: str,
825825
exclude_pattern: Optional[str] = None,
826826
remove_after: Optional[Union[timedelta, datetime]] = None,
827-
messages: Optional[List[BaseMESSAGE]] = [],
827+
messages: Optional[List[BaseMESSAGE]] = None,
828828
logging: Optional[bool] = False,
829829
interval: Optional[timedelta] = timedelta(minutes=1),
830830
auto_join: Optional[web.GuildDISCOVERY] = None,
@@ -834,7 +834,7 @@ def __init__(self,
834834
self.remove_after = remove_after
835835
self.invite_track = invite_track
836836
# Uninitialized template messages that get copied for each found guild.
837-
self.messages = messages
837+
self.messages = messages if messages is not None else []
838838
self.logging = logging
839839
self.interval = interval
840840
self.auto_join = auto_join
@@ -1090,15 +1090,15 @@ async def _advertise(self):
10901090
return GUILD_ADVERT_STATUS_SUCCESS
10911091

10921092
@misc._async_safe("_safe_sem", 1)
1093-
async def update(self, init_options = {}, _init = True, **kwargs):
1093+
async def update(self, init_options = None, _init = True, **kwargs):
10941094
"""
10951095
Updates the object with new initialization parameters.
10961096
10971097
.. WARNING::
10981098
After calling this method the entire object is reset
10991099
(this includes it's GUILD objects in cache).
11001100
"""
1101-
if len(init_options) == 0:
1101+
if init_options is None:
11021102
init_options = {"parent": self.parent}
11031103

11041104
await self._close()

src/daf/message/text_based.py

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,12 @@ class TextMESSAGE(BaseMESSAGE):
4242
4343
*start_in* now accepts datetime object
4444
45+
.. note::
46+
47+
Slow mode period handling:
48+
If the advertisement period is set less than the biggest slow-mode delay of the given channels,
49+
the period will be automatically set slightly above the slow-mode delay.
50+
4551
Parameters
4652
------------
4753
start_period: Union[int, timedelta, None]
@@ -121,7 +127,7 @@ def __init__(self,
121127
data: Union[Iterable[Union[str, discord.Embed, FILE]], str, discord.Embed, FILE, _FunctionBaseCLASS],
122128
channels: Union[Iterable[Union[int, discord.TextChannel, discord.Thread]], AutoCHANNEL],
123129
mode: Optional[Literal["send", "edit", "clear-send"]] = "send",
124-
start_in: Optional[Union[timedelta, datetime]] = datetime.now(),
130+
start_in: Optional[Union[timedelta, datetime]] = timedelta(seconds=0),
125131
remove_after: Optional[Union[int, timedelta, datetime]] = None):
126132
super().__init__(start_period, end_period, data, start_in, remove_after)
127133
self.mode = mode
@@ -365,11 +371,6 @@ async def _handle_error(self, channel: Union[discord.TextChannel, discord.Thread
365371
This method handles the error that occurred during the execution of the function.
366372
Returns `True` if error was handled.
367373
368-
Slow mode period handling:
369-
When the period is lower than the remaining time, the framework will start
370-
incrementing the original period by original period until it is larger then
371-
the slow mode remaining time.
372-
373374
Parameters
374375
-----------
375376
channel: Union[discord.TextChannel, discord.Thread]
@@ -524,7 +525,7 @@ async def _send(self) -> MessageSendResult:
524525

525526
@typechecked
526527
@misc._async_safe("update_semaphore")
527-
async def update(self, _init_options: Optional[dict] = {}, _init = True, **kwargs: Any):
528+
async def update(self, _init_options: Optional[dict] = None, _init = True, **kwargs: Any):
528529
"""
529530
.. versionadded:: v2.0
530531
@@ -561,7 +562,7 @@ async def update(self, _init_options: Optional[dict] = {}, _init = True, **kwarg
561562
else:
562563
kwargs["channels"] = [x.id for x in self.channels]
563564

564-
if not len(_init_options):
565+
if _init_options is None:
565566
_init_options = {"parent": self.parent}
566567

567568
await misc._update(self, init_options=_init_options, _init=_init, **kwargs)
@@ -657,7 +658,7 @@ def __init__(self,
657658
end_period: Union[int, timedelta],
658659
data: Union[str, discord.Embed, FILE, Iterable[Union[str, discord.Embed, FILE]], _FunctionBaseCLASS],
659660
mode: Optional[Literal["send", "edit", "clear-send"]] = "send",
660-
start_in: Optional[Union[timedelta, datetime]] = datetime.now(),
661+
start_in: Optional[Union[timedelta, datetime]] = timedelta(seconds=0),
661662
remove_after: Optional[Union[int, timedelta, datetime]] = None):
662663
super().__init__(start_period, end_period, data, start_in, remove_after)
663664
self.mode = mode
@@ -877,7 +878,7 @@ async def _send(self) -> MessageSendResult:
877878

878879
@typechecked
879880
@misc._async_safe("update_semaphore")
880-
async def update(self, _init_options: Optional[dict] = {}, _init = True, **kwargs):
881+
async def update(self, _init_options: Optional[dict] = None, _init = True, **kwargs):
881882
"""
882883
.. versionadded:: v2.0
883884
@@ -907,7 +908,7 @@ async def update(self, _init_options: Optional[dict] = {}, _init = True, **kwarg
907908
if "data" not in kwargs:
908909
kwargs["data"] = self._data
909910

910-
if not len(_init_options):
911+
if _init_options is None:
911912
_init_options = {"parent": self.parent}
912913

913914
await misc._update(self, init_options=_init_options, _init=_init, **kwargs)

src/daf/message/voice_based.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ def __init__(self,
114114
data: Union[AUDIO, Iterable[AUDIO], _FunctionBaseCLASS],
115115
channels: Union[Iterable[Union[int, discord.VoiceChannel]], AutoCHANNEL],
116116
volume: Optional[int] = 50,
117-
start_in: Optional[Union[timedelta, datetime]] = datetime.now(),
117+
start_in: Optional[Union[timedelta, datetime]] = timedelta(seconds=0),
118118
remove_after: Optional[Union[int, timedelta, datetime]] = None):
119119

120120
if not dtypes.GLOBALS.voice_installed:
@@ -387,7 +387,7 @@ async def _send(self) -> MessageSendResult:
387387

388388
@typechecked
389389
@misc._async_safe("update_semaphore")
390-
async def update(self, _init_options: Optional[dict] = {}, _init = True, **kwargs):
390+
async def update(self, _init_options: Optional[dict] = None, _init = True, **kwargs):
391391
"""
392392
.. versionadded:: v2.0
393393
@@ -424,7 +424,7 @@ async def update(self, _init_options: Optional[dict] = {}, _init = True, **kwarg
424424
else:
425425
kwargs["channels"] = [x.id for x in self.channels]
426426

427-
if not len(_init_options):
427+
if _init_options is None:
428428
_init_options = {"parent": self.parent}
429429

430430
await misc._update(self, init_options=_init_options, _init=_init, **kwargs)

src/daf/misc.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def _write_attr_once(obj: Any, name: str, value: Any):
3737
setattr(obj, name, value)
3838

3939

40-
async def _update(obj: Any, *, init_options: dict = {}, _init = True, **kwargs):
40+
async def _update(obj: Any, *, init_options: dict = None, _init = True, **kwargs):
4141
"""
4242
.. versionadded:: v2.0
4343
@@ -73,6 +73,9 @@ async def _update(obj: Any, *, init_options: dict = {}, _init = True, **kwargs):
7373
Other
7474
Raised from .initialize() method.
7575
"""
76+
if init_options is None:
77+
init_options = {}
78+
7679
# Retrieves list of call args
7780
init_keys = getfullargspec(obj.__init__.__wrapped__ if hasattr(obj.__init__, "__wrapped__") else obj.__init__).args
7881
init_keys.remove("self")

src/daf_gui/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33
from . import main
44

55
if __name__ == "__main__":
6-
main.run()
6+
main.run()

src/daf_gui/widgets/convert.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,12 @@ def __init__(self, class_, data: dict, real_object: object = None) -> None:
146146
self.data = data
147147
self.real_object = real_object
148148

149+
def __eq__(self, __value: object) -> bool:
150+
if isinstance(__value, ObjectInfo):
151+
return self.class_ is __value.class_ and __value.data == self.data and self.real_object is __value.real_object
152+
153+
return False
154+
149155
def __repr__(self) -> str:
150156
_ret: str = self.class_.__name__ + "("
151157
for k, v in self.data.items():

src/daf_gui/widgets/extra.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import tkinter as tk
1313
import ttkbootstrap.dialogs.dialogs as tkdiag
1414
import tkinter.filedialog as tkfile
15+
from ttkbootstrap.tooltip import ToolTip
1516

1617
import datetime as dt
1718

@@ -107,6 +108,7 @@ def _callback(*args):
107108
async_execute(old.real_object.update(**values), parent_window=frame.origin_window)
108109

109110
w.configure(command=_callback)
111+
ToolTip(w, "Update the actual object with new parameters (taken from this window)", topmost=True)
110112
w.pack(side="right")
111113

112114

@@ -122,6 +124,7 @@ def _callback(*args):
122124
frame.save_gui_values()
123125

124126
w.configure(command=_callback)
127+
ToolTip(w, "Load updated values from the object into the window", topmost=True)
125128
w.pack(side="right", padx=dpi_scaled(2))
126129

127130

0 commit comments

Comments
 (0)