Skip to content

Union type is not supported #267

Open
@tsuga

Description

@tsuga

I'm seeing an error when using Union type.

from typing import Union
from datafiles import datafile, Missing

@datafile("inventory/items/{self.name}.yml")
class InventoryItem:
    """Class for keeping track of an item in inventory."""

    name: str
    unit_price: float
    quantity_on_hand: Union[int, float] = 0

item = InventoryItem("widget", 3)
---------------------------------------------------------------------------
AssertionError                            Traceback (most recent call last)
[<ipython-input-4-9790d08ed9c3>](https://localhost:8080/#) in <module>()
     10     quantity_on_hand: Union[int, float] = 0.0
     11 
---> 12 item = InventoryItem("widget", 3)

3 frames
[/usr/local/lib/python3.7/dist-packages/datafiles/converters/__init__.py](https://localhost:8080/#) in map_type(cls, name, item_cls)
    134             converter = map_type(cls.__args__[0])
    135             assert len(cls.__args__) == 2
--> 136             assert cls.__args__[1] == type(None)
    137             converter = converter.as_optional()
    138 

AssertionError:

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions