Skip to content

Improve dataclass type hinting #78

Closed
@cretz

Description

@cretz

Is your feature request related to a problem? Please describe.

Our use of https://github.com/konradhalas/dacite is too primitive. It only supports to/from the object itself, not collections, optional, etc.

Describe the solution you'd like

All of the following should be supported via type hints:

  • MyDataClass
  • List[MyDataClass], Set[MyDataClass], other collections, etc
  • Mapping[str, MyDataClass], Dict[str, MyDataClass], other dicts, etc
  • Union[MyDataClass1, MyDataClass2], Union[List[int], Dict[str, MyDataClass]], etc
  • Optional[MyDataClass1], Optional[List[Dict[str, MyDataClass]]], etc

Here are the libraries found so far:

We should probably support customization via instance.to_json()/instance.to_dict() and Class.to_json()/Class.to_dict(). This means those using some of those other libraries will work automatically.

Needs investigation...

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions