fields() from DataClasses not working properly
See original GitHub issueHey I just wanted to ask about strange error I have. fileds() from dataclasses not working properly if dataclass is declared outside running function.
Minimalistic example:
DataClass in function
from dataclasses import dataclass, fields
import submitit
def run():
@dataclass
class Test:
test: str = "test"
u: int = 1
t = Test()
print(f"Test: {fields(t)}")
return 1
executor = submitit.AutoExecutor(folder="log_test")
executor.update_parameters(timeout_min=1, slurm_partition="dev")
job = executor.submit(run)
print(job.result())
print(job.stdout())
Print:
Test: (Field(name='test',type=<class 'str'>,default='test',default_factory=<dataclasses._MISSING_TYPE object at 0x7f5bceda6cd0>,init=True,repr=True,hash=None,compare=True,metadata=mappingproxy({}),_field_type=_FIELD), Field(name='u',type=<class 'int'>,default=1,default_factory=<dataclasses._MISSING_TYPE object at 0x7f5bceda6cd0>,init=True,repr=True,hash=None,compare=True,metadata=mappingproxy({}),_field_type=_FIELD))
DataClass outside function
from dataclasses import dataclass, fields
import submitit
@dataclass
class Test:
test: str = "test"
u: int = 1
def run():
t = Test()
print(f"Test: {fields(t)}")
return 1
executor = submitit.AutoExecutor(folder="log_test")
executor.update_parameters(timeout_min=1, slurm_partition="dev")
job = executor.submit(run)
print(job.result())
print(job.stdout())
Print:
Test: ()
The exact same thing happens on slurm cluster with python 3.7.4 and on my local computer without slurm with python 3.9. Is this submitit or threading issue?
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
python - Why is dataclass is not working correctly?
Checking sys.path shows that (1) is listed and therefore python should find the module dataclasses. I checked numpy (installed via pip) and it ......
Read more >dataclasses: ClassVar attributes are not working properly
I was trying to do something like @dataclass class A: x: ClassVar = set() and thanks to you I know it should be...
Read more >False Error Declaring Dataclass with Field Returned from a ...
PyCharm correctly infers that the return type of metadata is dataclasses.Field . However, because PyCharm cannot prove that default is not set, it...
Read more >How to use the dataclasses.field function in dataclasses
Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues...
Read more >Python dataclass inheritance, finally ! | by Anis Campos
Some of you might be thinking “I don't see the issue here, you just have to reorder you fields and problem solved!”. Well,...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Looks like we are all hitting this issue at the same time: https://github.com/facebookresearch/hydra/issues/1621
I think it should work if you move the dataclass to another file and that you import it.