File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11# General Python Stuff
22
3+ ## Weird data classes
4+
5+ This will work, as it recognises them as parameters when you type hint:
6+
7+ ```
8+ @dataclass
9+ class ASUArrivals:
10+ stroke: float = 1.2
11+ tia: float = 9.3
12+ neuro: float = 3.6
13+ other: float = 3.2
14+
15+ ASUArrivals(stroke=4)
16+ ```
17+
18+ But without, it recognises them as class attributes, and so won't work:
19+
20+ ```
21+ @dataclass
22+ class ASUArrivals:
23+ stroke = 1.2
24+ tia = 9.3
25+ neuro = 3.6
26+ other = 3.2
27+
28+ ASUArrivals(stroke=4)
29+
30+ --> TypeError: ASUArrivals.__init__() got an unexpected keyword argument 'stroke'
31+ ```
32+
33+ It doesn't do any validation with the type hints - you can say int, but it doesn't care if you use int, for example.
34+
35+ ```
36+ @dataclass
37+ class ASUArrivals:
38+ stroke: int = 1.2
39+ tia: float = 9.3
40+ neuro: float = 3.6
41+ other: float = 3.2
42+
43+ ASUArrivals(stroke=4.3)
44+ ```
45+
46+ If you miss type hints for any of them, they just get dropped from the class entirely
47+
48+ ```
49+ @dataclass
50+ class ASUArrivals:
51+ stroke: float = 1.2
52+ tia = 9.3
53+ neuro: float = 3.6
54+ other: float = 3.2
55+
56+ ASUArrivals()
57+ --> ASUArrivals(stroke=1.2, neuro=3.6, other=3.2)
58+ ```
59+
360## Jupyter notebook merge conflicts
461
562```
You can’t perform that action at this time.
0 commit comments