38
JohanO
8y

sometimes I hate python....

Ive just chased down a bug where a simple string saved in a simple dict sometimes came out as a f*cking tuple(!) when I needed it!

turned out that at some point this dict got updated with values from some other dict. And at some other point, I decided it was a great idea to rewrite that update code into individual setter's instead ... and of course forgot to remove one the trailing comma's, thus creating a perfectly legal tuple .... *sigh*

No errors, no warnings - just plain corrupt data....

Comments
  • 6
    That's a lot of green O.o
  • 1
    So you're blaming the language for doing what you told it to? Plus, setters other than setattr are pretty much the most unpythonic things there are.
  • 1
    @muffix this feature of the language is simply an example of bad UI. A pitfall.
  • 2
    Unit testing (unittest & pytest) has saved me more often than I'm willing to admit.

    Any function will take a bit more time to write because you need to add a test with expected inputs and outputs, but it will prevent you from breaking code in the future -- in practice this will save you incredible amounts of time. If you have a commercial app, it can even be worth it to hook it into deployment pipelines like jenkins or codeship, so you will never deploy broken code to a production/build server.
  • 4
    Static typing FTW!
  • 1
    @Re-cursing mypy, for example
  • 1
    L-l-l-l-linters!!
  • 1
  • 0
    That's why static- and strong-typing
Add Comment