Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 14155

Solved: Method association in python dataclass

$
0
0

I have to maintain code which uses dataclasses. In these, methods from libraries are imported and associated and I find the way it's done confusing and not very readable. It's done like this (a very simplified example) :

from dataclasses import dataclassfrom code.custom.package import method_a, method_b@dataclassclass myClass:    import numpy as np    var1: str    var2: str    var3: np.ndarray = NonemyClass.method_a = method_amyClass.method_b = method_b

The methods generally do operations on the data structures contained in the class.

Is this a common practice ? Is this the proper way to do this ? Or should this be avoided and done in another way ?


Viewing all articles
Browse latest Browse all 14155

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>