New submission from Wojciech Łopata <wlop...@gmail.com>:

I've checked this behaviour under Python 3.7.5 and 3.8.1.

```
from __future__ import annotations
from dataclasses import dataclass, fields

@dataclass
class Foo:
    x: int

print(fields(Foo)[0].type)
```

With annotations imported, the `type` field of Field class becomes a string 
with a name of a type, and the program outputs 'int'.

Without annotations, the `type` field of Field class is a type, and the program 
outputs <class 'int'>.

I found this out when using dataclasses_serialization module. Following code 
works fine when we remove import of annotations:

```
from __future__ import annotations
from dataclasses import dataclass
from dataclasses_serialization.json import JSONSerializer

@dataclass
class Foo:
    x: int

JSONSerializer.deserialize(Foo, {'x': 42})
```

TypeError: issubclass() arg 1 must be a class

----------
components: Library (Lib)
messages: 360611
nosy: lopek
priority: normal
severity: normal
status: open
title: from __future__ import annotations breaks dataclasses.Field.type
type: behavior
versions: Python 3.7, Python 3.8

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue39442>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to