Type Hinting Pandas Columns
ReamberPy builds on top of Pandas, and as such, it uses Pandas' DataFrame
to index and store data. This allows for our object to yield columns via the properties.
E.g. our OsuMap
stores bpms
as a DataFrame
.
Normally, we use bpms["bpm"]
to access the column, however, we can also use bpms.bpm
to access the column. This works too in DataFrames, however, it is never type-hinted.
ReamberPy works around this by performing meta-programming to not only generate the appropriate properties functions, but also create type-hinted .pyi
stubs.
Creating Properties via Decorators
We can create properties via decorators.
These decorators generates the new functions, however, as a result of decorators, the type-hints get broken. i.e. decorator-generated functions can't type-hint.
Python Stubs .pyi
To force type-hinting, we can create Python Stubs .pyi
files.
Combining Decorators with Python Stubs, you can create a simple code-base with extensive type-hinting.
Templating
Templating reduces the hinting of inheritables.
For example, using Generic
Yields
This is useful in propagating new types forward.