Python Type Hinting in Data Science Projects: A Must, a Maybe, or a No-No? | by Marcin Kozak | Sep, 2023


PYTHON PROGRAMMING

Should we use type hints in data-science projects realized in Python?

Whether or not you’re a happy user of type hinting in Python, you do have to know these concepts and how to use them. Photo by Kerin Gedge on Unsplash

Should we use type hints in data-science projects realized in Python?

Want a disclaimer? Here you are: It depends. In Proof-of-Concept types of projects, it’s often unnecessary. In production projects, at least in 2023, it rather is. But again, that depends.

I will try to be as concise as possible, and get to the point as fast as possible. I don’t want to spend hours on considering all pros and cons, for the simple reason that the data-science market has quite clear expectations of our work. My goal is to present these expectations to you, not to discuss them in detail.

Let’s start by stating the obvious. First of all, type hints in Python are optional. Optional like in you don’t have to use type hints in Python. If so, there’s only one answer to our main question: You can but no, you don’t have to use type hints in data science projects!

So… that’s it? Are we done here?

Wait a second. We did state the obvious, but we did not touch upon anything beyond the obvious.

Should we use type hints in data-science projects realized in Python? It depends. In Proof-of-Concept types of projects, it’s not necessary. In production projects, at least in 2023, it rather is.

An example. Imagine you’re a Python developer working for a private company. The company has its own rules and recommendations for Python development. One of the rules is: Use type hints. That’s it — irrespective of what you prefer, you have to use them. Had this been a recommendation, you wouldn’t have had to use them. However, since this is a rule, you have to use optional type hints.

Okay, good point. But we’re talking about type hints in data science projects in general, not in a particular company. So, optional, right? You don’t have to use them?



Source link

Be the first to comment

Leave a Reply

Your email address will not be published.


*