title: Python Pydantic - how to have an "optional" field but if present required to conform to not None value?
body: <p>I am trying to validate an object that has "optional" fields in the sense that they may or may not be present.  But when they are present, the fields should conform to a specific type definition (not None).</p>
  
  <p>In the example below, the "size" field is optional but allows None.  I want the "size" field to be optional, but if present it should be a float.</p>
  
  <pre><code>from pydantic import BaseModel
  
  class Foo(BaseModel):
      count: int
      size: float = None  # how to make this an optional float? 
  
   &gt;&gt;&gt; Foo(count=5)
   Foo(count=5, size=None)  # GOOD - "size" is not present, value of None is OK
  
  
   &gt;&gt;&gt; Foo(count=5, size=None)
   Foo(count=5, size=None) # BAD - if field "size" is present, it should be a float
  
   # BONUS
   &gt;&gt;&gt; Foo(count=5)
   Foo(count=5)  # BEST - "size" is not present, it is not required to be present, so we don't care about about validating it all.  We are using Foo.json(exclude_unset=True) handles this for us which is fine.
  </code></pre>