Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

6
  • 1
    Out of interest, when you say "the author of Counter opted to keep fromkeys and have it throw an exception rather than just remove the method" -- what would be the way to "remove a method" from a subclass in Python? I'm not sure I've ever seen it done, except maybe through monkey-patching a class after it's been defined, or by using a metaclass. Commented Sep 1, 2021 at 11:08
  • 1
    When I wrote that, I was thinking you could, but now I'm not sure at all. There are tricks to hide a method inherited from a parent class, but not to remove. On reflection, I'm going to rework that part of my answer. Commented Sep 2, 2021 at 1:33
  • 1
    Hopefully the new paragraph is more factual and helpful. (I'm realizing I had C++'s = delete feature in mind when I wrote that originally.) Commented Sep 2, 2021 at 1:53
  • 2
    Not a comment on your answer — but I find the documentation for NotImplementedError a little bizarre, frankly. I'm sure I've seen it used like that many times in the standard library, and I'd much prefer a helpful NotImplementedError message rather than the inexplicable NoneType is not callable error message you'd get if you replaced the method with None. It was also endorsed the other day by Raymond Hettinger on twitter, who's been a core dev for around 20 years now I believe! (I think he's also the author of Counter.) twitter.com/raymondh/status/1430565266136698882?s=21 Commented Sep 2, 2021 at 7:03
  • 1
    Yeah, I agree with you there, and I'm pretty sure I've seen it used that way in third-party libraries as well. I do see the utility in having something like the docs describe — a dedicated exception to indicate that you forgot something, kind of like Rust's todo!() macro — but then it would be handy to also have a NeverGonnaHappenError. Commented Sep 3, 2021 at 1:34