Better handling of typing.Literal
ealtamir opened this issue · 1 comments
ealtamir commented
I'm trying to derive the Spark schema of a BaseModel which I don't want to turn into a SparkModel, thus I'm creating a new model which subclasses from my original BaseModel and from SparkModel.
class MyClas(BaseModel):
is_this_a_field: Literal["yes", "no"]
class SparkMyClass(SparkModel, MyClass):
pass
When when trying to build a schema from SparkMyClass
I get
> if issubclass(t, Enum):
E TypeError: issubclass() arg 1 must be a class
To fix this I need to redefine the Literal
field in the base class.
My suggestion would be to add a check for Literal types and add a Spark field corresponding to the type of all the elements in the Literal, or fail if there's more than one type.
mitchelllisle commented