Skip to content

Tag: type-hinting

cx_Oracle connection type hinting in python

I’m diving into type hints and type hinting some of my code as I think it is a good practice. I have a function that takes both sqlalchemy and cx_Oracle connection/session objects. I was able to figure out the hinting for sqlalchemy here. Poked around some docs trying to figure it out with cx_Oracle to …

Python type hint for Iterable[str] that isn’t str

In Python, is there a way to distinguish between strings and other iterables of strings? A str is valid as an Iterable[str] type, but that may not be the correct input for a function. For example, in this trivial example that is intended to operate on sequences of filenames: Passing in a single filename would…

Python: use Type Hints together with Annotations

In Python, we all know Type hints, which became available from 2015: and we also know Function Annotations, in particular here I am referring to textual annotations like: But is it possible to use Type Hints together with a textual function annotation? For example: This last one throws an error. I cannot seem…

Type hint Pandas DataFrameGroupBy

How should I type hint in Python a pandas DataFrameGroupBy object? Should I just use pd.DataFrame as for normal pandas dataframes? I didn’t find any other solution atm Answer DataFrameGroupBy is a proper type in of itself. So if you’re writing a function which must specifically take a DataFrameGro…