Python Forum
Bug ? when dataclass field name == field type
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Bug ? when dataclass field name == field type
When I create a dataclass with same and field.type and assign a default value to None typehint get lost. I know that it does not respect naming convention but I have reasons to do so in my particular case.

Standard Behaviour
from dataclasses import dataclass
import typing
from typing import Optional, List, Tuple

class NotBuiltIn:
	test: str

class MyDataClass:
	field: Optional[NotBuiltIn] = None

{'field': typing.Union[__main__.NotBuiltIn, NoneType]}
Type hint get lost (variable name == type name) :
class layers:

class material:
    layers: Optional[layers] = None

{'layers': NoneType}
It looks like a bug but is it ?

Possibly Related Threads…
Thread Author Replies Views Last Post
  Display value in the another entry field instead of message box adisc 6 363 Jun-25-2022, 02:30 PM
Last Post: rob101
  magic related field in Django model sonh 1 346 Apr-24-2022, 12:37 PM
Last Post: sonh
  How to get datetime from numeric format field klllmmm 3 946 Nov-06-2021, 03:26 PM
Last Post: snippsat
  Auto increament in Entry field. in tkinter GUI cybertooth 7 1,662 Sep-17-2021, 07:56 AM
Last Post: cybertooth
  Display table field on multiple lines, 'wordwrap' 3python 0 869 Aug-06-2021, 08:17 PM
Last Post: 3python
  UPDATE SQLITE TABLE - Copy a fields content to another field. andrewarles 14 2,388 May-08-2021, 04:58 PM
Last Post: ibreeden
  drf ordering by custom field and add ranking in to_representation tomfong521 0 1,071 Mar-24-2021, 09:56 AM
Last Post: tomfong521
  finding element of specific field in pandas adjacency matrix amjass12 0 983 Oct-27-2020, 09:27 AM
Last Post: amjass12
  find a string in a field in MongoDB Leon79 2 1,378 Jul-19-2020, 09:20 PM
Last Post: menator01
  Find field name from all possible values kashcode 1 1,259 Apr-22-2020, 06:14 PM
Last Post: deanhystad

Forum Jump:

User Panel Messages

Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020