-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Closed
Labels
changeSuggested alteration to Pydantic, not a new feature nor a bugSuggested alteration to Pydantic, not a new feature nor a bugfeature request
Description
I encountered this while working on #2017:
from typing import List
from pydantic import BaseModel, Json
class JsonDemo(BaseModel):
# I'd expect this to work like typing.List[None], but at definition-time it raises
# RuntimeError: error checking inheritance of None (type: NoneType)
none: Json[None]
JsonDemo(none="null")
class JsonWorkaround(BaseModel):
# The workaround of using type(None) also fails at definition-time, raising
# RuntimeError: no validator found for <class 'NoneType'>, see `arbitrary_types_allowed` in Config
# The same error is apparent for List[None], so I think it's a more general bug
json_null: Json[type(None)]
list_of_none: List[None]I would expect both Json[None] and List[None] to work, accepting in respectively "null" or a list (or sequence) where all the elements are None - casting need not be supported because None is a singleton.
Jaakkonen
Metadata
Metadata
Assignees
Labels
changeSuggested alteration to Pydantic, not a new feature nor a bugSuggested alteration to Pydantic, not a new feature nor a bugfeature request