3 ms·
The binary "is spam" thing seems like a non-issue, unless I'm misunderstanding something. In Python you can easily implement Boolean attributes using predicates
by globular-toast 7mo ago
The binary "is spam" thing seems like a non-issue, unless I'm misunderstanding something. In Python you can easily implement Boolean attributes using predicates without breaking the API, like so:
@property
def is_spam(self) -> bool:
return self._comment_check in {"true", "blatant"}
Then you can simply add another predicate to support the blatant case:
@property
def is_blatant_spam(self) -> bool:
return self._comment_check == "blatant"
- 13hunteo 7mo agoIf you want to handle the three cases individually using your implementation, you would have to make another function call, rather than just the one
- globular-toast 7mo agoYou don't, although it is perhaps quite awkard: message.is_blatant_spam # true if blatant spam message.is_spam and not message.is_blatant_spam # true if possibly spam not message.is_spam # true if not spam But there's nothing stopping adding that middle one as another property, again without breaking compatibility: @property def is_possibly_spam(self) -> bool: return self.is_spam and not self.is_blatant_spam The point is, you don't actually have to break compatibility here, you can just define more predicates to add the extra granularity without breaking the existing ones.
- Someone 7mo agoAkismet provides a service and a Python library for calling that service. The service has 3 possible returns: not spam, likely spam, and definitely spam. Their library maps those 3 to 2: false, true. So, if you use their library, there’s no way to discriminate between likely spam and definitely spam. I wouldn’t consider rewriting the library for such a simple change, though. Yes, changing the existing function to return a three-valued result would be a breaking change, but adding a new entrypoint that does that, although technically a breaking change (that’s discoverable by reflection) would not be a breaking change. I also don’t see why introducing asynchrony would require a rewrite. It could just be bolted on in new entry points, which, I think, the author actually did (“So I made the decision to have two client classes, one sync and one async. As a nice bonus, this meant I could do all the work of rewriting in new classes with new names. That would let me mark the old Akismet class as deprecated but not have to immediately remove it or break its API”)