in Education by
from datetime import date import dataclasses @dataclasses.dataclass(frozen=True) class A: date: date = dataclasses.field() Traceback (most recent call last): File "", line 1, in File "/usr/local/Cellar/python/3.7.7/Frameworks/Python.framework/Versions/3.7/lib/python3.7/dataclasses.py", line 1002, in wrap return _process_class(cls, init, repr, eq, order, unsafe_hash, frozen) File "/usr/local/Cellar/python/3.7.7/Frameworks/Python.framework/Versions/3.7/lib/python3.7/dataclasses.py", line 979, in _process_class str(inspect.signature(cls)).replace(' -> None', '')) File "/usr/local/Cellar/python/3.7.7/Frameworks/Python.framework/Versions/3.7/lib/python3.7/inspect.py", line 3040, in __str__ formatted = str(param) File "/usr/local/Cellar/python/3.7.7/Frameworks/Python.framework/Versions/3.7/lib/python3.7/inspect.py", line 2558, in __str__ formatannotation(self._annotation)) File "/usr/local/Cellar/python/3.7.7/Frameworks/Python.framework/Versions/3.7/lib/python3.7/inspect.py", line 1199, in formatannotation return repr(annotation) File "/usr/local/Cellar/python/3.7.7/Frameworks/Python.framework/Versions/3.7/lib/python3.7/dataclasses.py", line 249, in __repr__ return ('Field(' File "/usr/local/Cellar/python/3.7.7/Frameworks/Python.framework/Versions/3.7/lib/python3.7/dataclasses.py", line 249, in __repr__ return ('Field(' File "/usr/local/Cellar/python/3.7.7/Frameworks/Python.framework/Versions/3.7/lib/python3.7/dataclasses.py", line 249, in __repr__ return ('Field(' [Previous line repeated 491 more times] RecursionError: maximum recursion depth exceeded But this works: @dataclasses.dataclass(frozen=True) class A: date: date So does this: @dataclasses.dataclass(frozen=True) class A: date_: date = dataclasses.field() Is that a bug, or by design? Select the correct answer from above options

1 Answer

0 votes
by
 
Best answer
This: date: date = dataclasses.field() doesn't annotate date as datetime.date. It annotates date as dataclasses.field(), because annotation is evaluated after assignment. dataclasses doesn't expect the field to have itself as its annotation, and you didn't want that either. Use something like import datetime import dataclasses @dataclasses.dataclass(frozen=True) class A: date: datetime.date = dataclasses.field() If you want to know more about the Data Science then do check out the following Data Science which will help you in understanding Data Science from scratch

Related questions

0 votes
    I have this following datetime64[ns] type timestamps. x1=pd.Timestamp('2018-04-25 00:00:00') x2=pd.Timestamp('2020- ... -04-25 00:53:00 Select the correct answer from above options...
asked Jan 9, 2022 in Education by JackTerrance
0 votes
    I have no clue why is this getting failed datetime.datetime.strptime( date_string, ' %A %d %B %Y : %I:%M %p ... help me solve this Select the correct answer from above options...
asked Jan 9, 2022 in Education by JackTerrance
0 votes
    If I use a while loop for my below code, it is not giving the desired output, but when i use for loop i am anle ... x += 1 print(Comm) Select the correct answer from above options...
asked Jan 9, 2022 in Education by JackTerrance
0 votes
    It is a principal question, regarding the theory of neural networks: Why do we have to normalize the input for ... is not normalized? Select the correct answer from above options...
asked Jan 27, 2022 in Education by JackTerrance
0 votes
    I am getting errors for the code when running it on a 'tips' dataset but I can run it on a tulips dataset ... . Am I missing something? Select the correct answer from above options...
asked Jan 19, 2022 in Education by JackTerrance
0 votes
    Can anyone tell me why Python is better than R for Data Science? Select the correct answer from above options...
asked Jan 19, 2022 in Education by JackTerrance
0 votes
    Can anyone tell me why Python is used in Data Science? Select the correct answer from above options...
asked Jan 19, 2022 in Education by JackTerrance
0 votes
    When I run pip3 install -r requirements.txt on the project I get this error message: pip._vendor.pkg_resources. ... on my machine. Select the correct answer from above options...
asked Jan 19, 2022 in Education by JackTerrance
0 votes
    Here's the code: ''' file_path = (r'C:\Users\Luka\Desktop\Pyhton exercises\pi_digits.txt') with open( ... file_object: print(line) Select the correct answer from above options...
asked Jan 19, 2022 in Education by JackTerrance
0 votes
    Working on this problem for a python course and can't for the life of me figure out why this doesn't work. It ... seen in index = 0 Select the correct answer from above options...
asked Jan 11, 2022 in Education by JackTerrance
0 votes
    In the python documentation, an instance of a named_tuple is created by using the below code: Point = named_tuple(' ... of doing it? Select the correct answer from above options...
asked Jan 10, 2022 in Education by JackTerrance
0 votes
    I have just built my first model using Keras and this is the output. It looks like the standard output you get ... - loss: 0.1928 Select the correct answer from above options...
asked Feb 1, 2022 in Education by JackTerrance
0 votes
    Can anyone tell me what qualifications does a Data Scientist need? Select the correct answer from above options...
asked Jan 17, 2022 in Education by JackTerrance
0 votes
    How do I pickle an instance of a frozen dataclass with __slots__? For example, the following code raises an ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 17, 2022 in Education by JackTerrance
0 votes
    Suppose I have a Tensorflow tensor. How do I get the dimensions (shape) of the tensor as integer values? I ... 'Dimension' instead. Select the correct answer from above options...
asked Feb 8, 2022 in Education by JackTerrance
...