konradhalas / dacite

Simple creation of data classes from dictionaries.
MIT License
1.72k stars 106 forks source link

`WrongTypeError` - `should be "str" instead of value ... of type "int"` - Important when loading data from yaml #254

Open JakeSummers opened 5 months ago

JakeSummers commented 5 months ago

To Reproduce

def test_thing():

    @dataclass
    class Thing:
        foo: str

    input = yaml.safe_load(
        """
        foo: 8790666
        """
    )

    # WHEN
    dacite.from_dict(Thing, input)

    # THEN - NO EXCEPTION IS THROWN

Adding some characters into the test data, makes the above code work.

    input = yaml.safe_load(
        """
        foo: 8790666AAA
        """
    )

Expected behavior

No exception should be thrown.

Environment

Additional context

I think that the same argument applied in #74 could apply here. :)

JakeSummers commented 5 months ago

After thinking about this a bit furter, I am not sure that this is a bug.

Updating the yaml from:

foo: 8790666

To:

foo: '8790666'

Resolves the problem.

It probably doesn't make sense to fix this issue. Suggestion: Close this issue.