[New-bugs-announce] [issue36363] Wrong type when missname dataclass attribute with existing variable name

Bastien Sevajol report at bugs.python.org
Tue Mar 19 09:29:50 EDT 2019


New submission from Bastien Sevajol <sevajol.bastien at gmail.com>:

Hello,

For following code:

```
import dataclasses
import typing
from datetime import datetime


@dataclasses.dataclass
class Foo:
    datetime: typing.Optional[datetime] = None


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

`datetime` `Foo` attribute have `NoneType` type. Problem come from `datetime` attribute name is already used by the `from datetime import datetime` import. I'm not sure if it is a bug or a strange behavior but it seems not regular. Tested on python 3.8.0a2 with same result.

----------
components: Extension Modules
messages: 338354
nosy: Bastien Sevajol
priority: normal
severity: normal
status: open
title: Wrong type when missname dataclass attribute with existing variable name
type: behavior
versions: Python 3.7

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue36363>
_______________________________________


More information about the New-bugs-announce mailing list