sopel-irc / sopel

:robot::speech_balloon: An easy-to-use and highly extensible IRC Bot framework. Formerly Willie.
https://sopel.chat
Other
951 stars 405 forks source link

memories: test/fix interactions between `SopelIdentifierMemory` ↔ `dict` #2525

Closed dgw closed 8 months ago

dgw commented 8 months ago

Description

Tin. Will resolve #2524.

Checklist

Notes

Started as a partial, untested fix from my tablet to reserve the PR number. New day, new task list:

dgw commented 8 months ago

Fix for pop() looks reasonable to me.

Fun fact: It wasn't reasonable, and in fact didn't raise KeyError if the key is missing and no default was provided.

Fixed that, and checked off some more of my task list w/fixes for .copy(), del memory['KeY'], and .get().

Still draft, though. I have several more behaviors to retest and then fix if necessary.

dgw commented 8 months ago

Think I'm about burned out on this for the day. But if my notes are correct, only __eq__()/__ne__() and setdefault() are left to check/unit-test/maybe-fix. πŸŽ‰

dgw commented 8 months ago

Turns out I lied about being done for the day. setdefault() was a pretty simple one, and then after toying with __eq__() for a bit I just decided not to bother.

Objects of different types probably should be considered unequal, unless there's a really good use-case I'm missing. (Anyone who really wants to force a comparison between a regular dict and a SopelIdentifierMemory can test identifier_memory == SopelIdentifierMemory(my_normal_dict) instead, since this patch fixes that behavior.)

dgw commented 8 months ago

Aha, need to decide what to do about those "assert statement has a side effect" errors from CodeQL. Now that I eliminated the intermediate variables from those tests, I don't really want to put them back. πŸ˜…

Exirel commented 8 months ago

Objects of different types probably should be considered unequal

In this case, absolutely, yes. A SopelIdentifierMemory is a very specific structure that has a very specific behavior. If people are going to do weird stuff with it, that weird stuff shouldn't work.

dgw commented 8 months ago

Welp, looks like no more CI builds on this branch until I rebase. Y'all mind if I squash out the fixups at the same time?

Exirel commented 8 months ago

Yes go ahead, this will fix the conflict too.

dgw commented 8 months ago

this will fix the conflict too

Yep, that's why I wanted to rebase. Hard to continue bikeshedding new test cases if CI won't run any more. 😝

Ran 3.10 & 3.8 tests locally; pushing in a moment, once I review the final history for rebase mistakes… I wound up doing three passes on it so there'd be less chance of putting fixups in the wrong order by accident, and I'm still not quite positive that I put everything in the right order. πŸ˜…

dgw commented 8 months ago

Got carried away and used git rebase --exec to run lint + tests on Python 3.11 for every commit in the cleaned-up history.

But because of that, I know every intermediate step works as expected and doesn't have any dangling imports or commits that were reordered incorrectly. :)

Edit: Why oh why did Python 3.8 linting fail? I specifically checked it before the whole --exec thing under 3.11! 😠

Edit 2: Fixed, of course. My linter fixup commit must have gotten lost somewhere in the rebase. Comparison locally of the old HEAD (ae6c337c9b8da4c3ac59a0502f1eb2e789ed70ae) vs. current HEAD shows that no other changes slipped. I must have screwed up a conflict resolution and pasted the old MemoryConstructorInput line on top of the fixed one.

dgw commented 8 months ago

I have another rebase in my future, apparently. Hopefully @SnoopJ can revisit the one or two open threads he started by the time Exi comes back from being "AFK" (as he said) for a few days, and I can rebase one last time with all the feedback/fixups then.

dgw commented 8 months ago

The fixups I just pushed (plus one technically unrelated new test I'm shoehorning in) catch even more edge cases that were missed, which @SnoopJ's nitpicks nudged me to find either directly or indirectly. Another very helpful review, thanks!

dgw commented 8 months ago

Latest force-push to squash out all the fixups moved one of the tests within the file, but meh. I made sure that the commit order is sane using git rebase master --exec '<pip3 deps> && <run lint/test>' and all the intermediate stages pass. I verified each commit's diff manually to be even more sure that the intermediate steps make logical sense. Can't imagine what else I could double check at this point, so let's :shipit:

Note: if you really really want a nitpick at this point, I still don't think it's necessary to do any assertion about how a builtin dict works.

I reduced the number of those, if not completely eliminated them. You're right that it isn't worth delaying the patch any longer.