3 ms·
I think it's because I'm working with elm right now, but this kind of thing scares me: created: datetime But if type(self.created) is str: self
by kuon 9y ago
I think it's because I'm working with elm right now, but this kind of thing scares me:
created: datetime
But
if type(self.created) is str:
self.created = dateutil.parser.parse(self.created)
So basically, the type annotation cannot be trusted.
- owaislone 9y agoNo, they can't be but Python doesn't pretend that they do. They are just that, annotations. They don't ensure correctness. It's up to other programs to analyze (like mypy) and warn during development. That's it.
- bunderbunder 9y agoIn Python, type annotations are (expressly) just a special type of comment that's been given a regularized format for the sake of both human and computer readability. I don't know that it should scare you, but, like with many Python features, it's something that should be approached in a sensible manner. The Python philosophy is to leave you with the freedom to monkey around, and leave it to you to decide whether you want to abuse that ability. (Look at me, all talking like someone who didn't spend 2 hours diagnosing a type error that a static language would have found and forced me to fix within half a second. :P )