I am working on release 3.7.1 of the Transcrypt Python to JavaScript compiler. Part of the release procedure is a shipment test, in which Transcrypt is tested back to back with CPython.
It used to run flawlessly with the beta's of CPython 3.7, but with the release there's a problem.
The program:
from dataclasses import dataclass
from typing import ClassVar
@dataclass
class Test:
x: ClassVar = 10
y: int = 10
t = Test ()
t.x = 20
print (repr (t))
used to print (using CPython):
Test(x=20, y=10)
but with the release it prints (again just using CPython):
Test(y=10)
So it leaves out the class variable x from the representation. Can anyone tell my whether or not this change is intentional, and where I can find a discussion that justifies it?
With this change Transcrypt behaves differently from CPython, which I don't want. So I wonder should I adapt Transcrypt or should I consider this a CPython regression and wait for it to be solved.
From the documentation:
30.6.3. Class variables
One of two places where
dataclass()
actually inspects the type of a field is to determine if a field is a class variable as defined in PEP 526. It does this by checking if the type of the field istyping.ClassVar
. If a field is aClassVar
, it is excluded from consideration as a field and is ignored by the dataclass mechanisms. SuchClassVar
pseudo-fields are not returned by the module-levelfields()
function.
So, this appears to be an intentional change.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With