Adding a unit to a converter should not mean hunting through UI and calculation code. Keep the supported quantities, units, and conversion factors in one configuration file. Other parts of the app should read that file rather than name specific units themselves. section 3.5.2
unit_config = {
"Mass": {
"Kilograms": 1, # Standard unit
"Grams": 0.001,
"Pounds": 0.453592,
# ...
},
"Length": {
"Meters": 1, # Standard unit
"Centimeters": 0.01,
# ...
},
}
A nested dictionary shows the basic arrangement: each quantity has units, and each unit has a conversion factor relative to its standard unit. section 3.6.2
When units also need abbreviations and quantities need an explicitly named standard unit, use Unit and Quantity dataclasses. In unit_config.py, each quantity then holds its standard-unit name and a dictionary of units with their abbreviations and factors. section 3.6.2
The same configuration serves both sides of the app: its quantity names populate the selector, its units populate the dropdowns, and its factors let the backend calculate a result. To support another unit, add it in the configuration rather than hard-coding it into the UI. section 3.5.3 section 3.5.2






















