Splitting a class with static methods

It is probably a question more of fastcore, but it is on the nbdev dev environment that I need it.
I have a class with many constructors as @classmethod of the style from_csv, from_file, etc…
They are long and complex, so I wanted to split the cells and test them separately. Can I do so with patch or patch_to?
Something like:

class foo():
  def __init__(self, params): pass

  def from_csv(cls, csv_file): 
    params = read_csv(csv_file)
    return cls(params)

Do some doc, examples and tests, and add a new class method later:

def from_file(cls, file)
  params = get_params_from_file(file)
  return cls(params)

This does not work, but probably I am not that far away…

The syntax is wrong. You have to write:

def from_file(cls:foo, file)
  params = get_params_from_file(file)
  return cls(params)

I’m not sure that works either?

Ah! That’s annoying. I as sure I had been able to patch @classmethod before though.

1 Like

Maybe it is something not that useful?
This appears to do the trick: