smarie / python-pyfields

Define fields in python classes. Easily.
https://smarie.github.io/python-pyfields
BSD 3-Clause "New" or "Revised" License
45 stars 10 forks source link

`@autofields` does not take definition order into account #76

Closed smarie closed 4 years ago

smarie commented 4 years ago

Consider this:

from pyfields import autofields, get_fields

@autofields
class Foo:
    c: int
    b: str = "hello"

get_fields(Foo)  # <-- (<NativeField: Foo.b>, <NativeField: Foo.c>)

So the order in which the fields are returned is wrong.

smarie commented 4 years ago

After investigating, this bug only happens when there are attributes that do not have default values (only an annotation).