Plus it also looks like the author has thought this through in a very comprehensive manner:
* Using contexts for unit redefinition
The exact definition of a unit of measure can change slightly depending on the country, year, and more in general convention. For example, the ISO board released over the years several revisions of its whitepapers, which subtly change the value of some of the more obscure units. And as soon as one steps out of the SI system and starts wandering into imperial and colonial measuring systems, the same unit may start being defined slightly differently every time - with no clear ‘right’ or ‘wrong’ definition.
The default pint definitions file (default_en.txt) tries to mitigate the problem by offering multiple variants of the same unit by calling them with different names; for example, one will find multiple definitions of a “BTU”:
british_thermal_unit = 1055.056 * joule = Btu = BTU = Btu_iso
international_british_thermal_unit = 1e3 * pound / kilogram * degR / kelvin * international_calorie = Btu_it
thermochemical_british_thermal_unit = 1e3 * pound / kilogram * degR / kelvin * calorie = Btu_th
That’s sometimes insufficient, as Wikipedia reports no less than 6 different definitions for BTU, and it’s entirely possible that some companies in the energy sector, or even individual energy contracts, may redefine it to something new entirely, e.g. with a different rounding.
Pint allows changing the definition of a unit within the scope of a context. This allows layering; in the example above, a company may use the global definition of BTU from default_en.txt above, then override it with a customer-specific one in a context, and then override it again with a contract-specific one on top of it.*
> The exact definition of a unit of measure can change slightly depending on the country, year, and more in general convention
How truly wonderful. I’m delighted to see this level of diligence. Too often you see these “clickbait” libraries that seem to do something great but then you scratch the surface and see there’s a lot of stuff not fully thought out.
It's reasonable to say that although strictly SI definitions changed (and will continue to be refined now that they're all in terms of a known constant, our certainty as to the value of these constants will gradually improve) in practice you don't care.
Take the kilogram for example, the definition of the kilogram drifted until the relatively recent decision to define it based on the Planck constant (because previously it used physical Prototypes and those are subject to change over time like any object), but the drift was tiny, less than 30ppm over centuries. If you have an ordinary mass of something, the drift in definition of the kilogram makes far less difference than inaccuracies of your measuring scales, dust settling on the object measured and other factors.
You don't in fact care whether that's a 1885 kilogram of potatoes or a 2021 kilogram of potatoes, because you won't be measuring potatoes to a precision where the difference matters.
In contrast you would presumably care whether you were served a US pint of beer of ~473ml or a UK pint of beer of ~568ml. Quite a difference to a hobbit at least.
Plus it also looks like the author has thought this through in a very comprehensive manner:
* Using contexts for unit redefinition
The exact definition of a unit of measure can change slightly depending on the country, year, and more in general convention. For example, the ISO board released over the years several revisions of its whitepapers, which subtly change the value of some of the more obscure units. And as soon as one steps out of the SI system and starts wandering into imperial and colonial measuring systems, the same unit may start being defined slightly differently every time - with no clear ‘right’ or ‘wrong’ definition.
The default pint definitions file (default_en.txt) tries to mitigate the problem by offering multiple variants of the same unit by calling them with different names; for example, one will find multiple definitions of a “BTU”:
british_thermal_unit = 1055.056 * joule = Btu = BTU = Btu_iso international_british_thermal_unit = 1e3 * pound / kilogram * degR / kelvin * international_calorie = Btu_it thermochemical_british_thermal_unit = 1e3 * pound / kilogram * degR / kelvin * calorie = Btu_th That’s sometimes insufficient, as Wikipedia reports no less than 6 different definitions for BTU, and it’s entirely possible that some companies in the energy sector, or even individual energy contracts, may redefine it to something new entirely, e.g. with a different rounding.
Pint allows changing the definition of a unit within the scope of a context. This allows layering; in the example above, a company may use the global definition of BTU from default_en.txt above, then override it with a customer-specific one in a context, and then override it again with a contract-specific one on top of it.*