by ReflectedImage · 4y ago · 0 comments
For reference, don't do either of those things in Python.
And there is nothing wrong with using a type checker for your Python type annotations.
"And there is nothing wrong with using a type checker for your Python type annotations."
There is a lot wrong with that. Python is a dynamically typed language. If you are using a static type checker on a dynamically typed language, you are not taking advantage of the dynamic nature of the language.
You are basically not writing Python code at all. This means you get all the disadvantages of using a dynamically typed language with none of the benefits.
In summary, you have a made a very poor engineering decision.
Typing related bugs that aren't caught in unit testing are very rare.
I really dislike this take. I believe Python is about rapid iteration, doing more of functionality with less code, and enjoying the process of programming. You know what I enjoy? Easily knowing what features (methods, attributes, keys) an object has. You know what I really don't enjoy? Having to dig through reams of source code to figure out what attributes I can use, or what *kwargs a function takes.
Nothing about duck typing prohibits saying `def func(duck: Duck)`, because maybe it's a French duck and has .coin() instead of .quack().
Also also, how is static typing completely incompatible with dynamic features? Usually there exists an abstraction with static types that actually captures the behavior you want. Its rare you want to be able to handle literally anything. Ask oneself, "could this function receive absolutely, truly, anything, or is it just shortcut for not finding the right types?"
"Having to dig through reams of source code to figure out what attributes I can use, or what *kwargs a function takes."
Figuring out the attributes and what kwargs a function takes is the role of your intelligent IDE and docstrings. You think you need to static typing for this since you haven't spent the time to learn how Python does these things.
Duck typing says, duck doesn't have a type, not even Duck, anything that quacks is a duck even a 115 ton truck.