dtudk / lc-power-match-baluns

Python package and notebooks for power matching LC-baluns
GNU Lesser General Public License v2.1
0 stars 0 forks source link

Create a classmethod instead #1

Closed zerothi closed 11 months ago

zerothi commented 12 months ago

https://github.com/dtudk/lc-power-match-baluns/blob/0fdf0f8963e6a960c4c8f0fb3e3a7401ad990052/src/lc_power_match_baluns/oneport.py#L119

Just a suggestion, why not a classmethod?

thePlasm commented 11 months ago

There was no particular reason that I used staticmethods over classmethods as they both work. Are there any advantages for using classmethods over staticmethods in this case?

zerothi commented 11 months ago

The advantage is that when you subclass it will return based on the class:

@classmethod
def from_reactance_at_frequency(cls, reactance: float,
      frequency: float, index: int | None = None) -> Capacitor:
    value = -1 / (2 * math.pi * frequency * reactance)
    return cls(value, index)
zerothi commented 11 months ago

Otherwise the advantage is just the clarity of the method, but that is perhaps a preference thing.