funkybob / gilbert

A simple static site generator.
https://gilbert.readthedocs.io/en/latest/
MIT License
10 stars 4 forks source link

Marking metadata as optional #27

Open shuttle1987 opened 5 years ago

shuttle1987 commented 5 years ago

Let's say we have a page that could contain socialURL but this may not be present always, how should we go about marking this?

import typing
class ExamplePage1(Templated, Content):
    socialURL: typing.Union[None, dict]
import typing
class ExamplePage2(Templated, Content):
    socialURL: typing.Optional[dict]

Is one of these is preferable to the other?

funkybob commented 5 years ago

Had to re-read the typing docs myself. I find the two following references:

You can use Optional[X] as a shorthand for Union[X, None].
Optional[X] is equivalent to Union[X, None]

So it seems both are acceptable. If the schema module doesn't currently support this, that's a bug.

funkybob commented 5 years ago

Did either of these work as you expected ? If so, please close this issue. If not, please provide more details :)