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
  UPDATE SQLITE TABLE - Copy a fields content to another field. andrewarles 14 743 May-08-2021, 04:58 PM
Last Post: ibreeden
  drf ordering by custom field and add ranking in to_representation tomfong521 0 350 Mar-24-2021, 09:56 AM
Last Post: tomfong521
  finding element of specific field in pandas adjacency matrix amjass12 0 384 Oct-27-2020, 09:27 AM
Last Post: amjass12
  find a string in a field in MongoDB Leon79 2 685 Jul-19-2020, 09:20 PM
Last Post: menator01
  Find field name from all possible values kashcode 1 625 Apr-22-2020, 06:14 PM
Last Post: deanhystad
  Field with dynamic id not found at playback pythonscripting 0 533 Feb-20-2020, 02:43 PM
Last Post: pythonscripting
  Add path to a local file in pop-up field pythonscripting 1 692 Feb-08-2020, 10:57 PM
Last Post: Larz60+
  Creating a set with dataclass and dict hobbitdur 11 3,363 Jan-16-2020, 11:22 AM
Last Post: buran
  Type hinting - return type based on parameter micseydel 2 972 Jan-14-2020, 01:20 AM
Last Post: micseydel
  text box field vishnu 4 917 Oct-04-2019, 06:38 AM
Last Post: vishnu

Forum Jump:

User Panel Messages

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