1

I am creating a configuration management system in python and are exploring options between hydra/pydantic/both. I get a little confused over when to use MISSING versus just leaving it blank/optional. I will use an example of OmegaConf here since the underlying structure of hydra uses it.

@dataclass
class User:
    # A simple user class with two missing fields
    name: str = MISSING
    height: Height = MISSING

where it says that this MISSING field will convert to yaml's ??? equivalent. Can I just leave it blank?

ilovewt
  • 911
  • 2
  • 10
  • 18
  • 1
    What I don't quite get is why the example they give, `another_num: int = MISSING` doesn't cause a mypy type checking error, since `MISSING` is actually defined as `"???"` in `omegaconf.py`. Looking forward to someone answering your question. – joanis Jan 12 '23 at 12:43
  • From the docs `Omitting a default value is equivalent to assigning MISSING to it, although it is sometimes convenient to be able to assign MISSING it to a field.` https://hydra.cc/docs/1.1/tutorials/structured_config/config_groups/#missing-fields – Nikolay Hüttenberend Jan 12 '23 at 12:59
  • @NikolayManolov Yeap saw that as well, I am still unsure how this `MISSING` makes it more convenient, is it somewhere down the pipeline that this becomes useful/apparent? – ilovewt Jan 12 '23 at 13:00
  • 2
    Hmm, I don't have a particular usecase in mind. But usually, you can't have fields without a default value after fields with default values (in the order of fields for a partiular dataclass), so assigning MISSING makes your field technically have a default value, which internally is handled as no-value. I guess it could also be somehow useful for code validation/anlysis, etc. – Nikolay Hüttenberend Jan 12 '23 at 13:04

0 Answers0