News for hackers. Stuff that matters.
Re:Atlas, a hopefully better engineering IDE by heisenzombie on Monday May 10, 2021 @11:45PM (#27113996)
I regularly use "pint" for Python:

https://pint.readthedocs.io/en/stable/

I'm sure it's not as good as a true type system could be, but it works pretty transparently due to Python's duck typing.

Re:Atlas, a hopefully better engineering IDE by techdragon on Tuesday May 11, 2021 @12:25AM (#27114206)
I’ll second the utility of “pint” for anything unit or quantity related in Python.

I’m literally in the middle of writing a rate limited continuously run service wrapper around some existing one shot task code and while I initially thought about just parsing the rate definition out myself because it’s pretty simple to just split on “/“ or “per”, but after thinking through the usage scenarios I just ended up using pint to convert anything it can understand as a frequency.

So anything of the form x / time unit or x per time unit, and converting it to the appropriate scale for use by the rest of my code. A whole bunch of string matching code replaced by a one line (two if I count the defensive unit type check to prevent false positive parsing problems) that looks as simple as this…

  default_sleep_interval = (1/ureg(default_rate)).to(“seconds”).magnitude