python-desert / desert

Deserialize to objects while staying DRY
https://desert.readthedocs.io
MIT License
158 stars 10 forks source link

Allow excluded fields to have no typehints? #97

Open sveinse opened 4 years ago

sveinse commented 4 years ago

Should it be possible to omit typings on fields which are excluded from the schema? Consider the following test. This code currently fails with desert.exceptions.UnknownType: Desert failed to infer the field type for None.

def test_typing_missing():
    """Test exluded field

    """

    @attr.s
    class A:
        x: int = attr.ib()
        y = attr.ib()

    schema = desert.schema_class(A, meta={'exclude': ('y')})()
    loaded = A(x=1, y=None)
    actually_dumped = {"x": 1}

    assert schema.dump(loaded) == actually_dumped
python-desert commented 4 years ago

That sounds like a good idea.