Notable Change
Hello, loves!
I’ve made a notable change to PubSub, with more to come. Keyword arguments. Small apology for poor testing.
I’ve noticed that when setting up callbacks with PubSub, I often get the parameters wrong. A note on a card here says “Checking for PubSub parameters”, and I decided to take a cut at that. After a bit of exploring and printing, I began, in several steps, to change over to keyword arguments. As things stand now, here is how one publishes an event:
def interact_with_player(self, dungeon) -> bool:
self.state = (self.state+1)%len(self.resources)
dungeon.publish('state_number', self.name, content=self, state=self.state)
return self.enterable
You now provide the parameters beyond the event and caller_id with keywords. (Possibly we should require the other two as well: I’ve not decided yet.)
My tentative plan is that when one defines a new PubSub message, the done thing will be to add an entry to a structure in the PubSub object that includes the event name and the required parameter keywords, and that we’ll check publish calls for matching at run time. I have not been able to think of a way to check them at compile time, unless we were to have a unique publish_state_number method added to PubSub for every publication, which doesn’t feel right to me.
The PubSub didn’t have to change much, just removing the *args references throughout. What was more troubling, and this is becoming far too common, was that there aren’t many tests that exercise all the publish and subscribe calls in the system, so I had to wander around the dungeon stepping on things to find all the places where the calls were not right. I have not found a way to convince PyCharm to recognize calls that aren’t right, at least not yet.
Possibly if we required full keyword arguments, with event= and caller_id=, we’d get better warnings.
I’ll try that next time, and begin to fill in the run-time checking if it’s still needed. For now, I’m done coding and reporting.
It’s troubling how far behind the tests are lagging. The objects are so inter-tangled that writing tests is difficult, so I write fewer than are needed. Something must be done about this. And unfortunately, I am the one who has to do it.
- Apology
-
I do try always to live up to my own standards, and here and elsewhere in life, often I fall short. Sometimes, too far short, and that’s where we are now. I’ll try to pick up the slack.