title: Frozen dataclass pathlib.Path-like initialization
body: <p>I have this dataclass:</p>
  <pre><code>@dataclass(frozen=True)
  class CacheSchema:
      id_key: str
      snapshot_key: str | None
      version: str = Info.Versions.schema_cache
  </code></pre>
  <p>and I would like to initialize it the same way <code>pathlib.Path</code> does it, so either pass the required arguments or an already initialized <code>CacheSchema</code> object. From my limited understanding I figured I would have to customize <code>__new__()</code>, so I did, however I can't do it exactly as <code>Path</code> does it because the dataclass is frozen and I'm not supposed to change the values after creation. So I came up with this:</p>
  <pre><code>def __new__(cls, *args, **kwargs):
      if len(args) == 1 and type(args[0]) is cls:
          return cls.__new__(cls, args[0].id_key, args[0].snapshot_key, args[0].version)
  
      return super(CacheSchema, cls).__new__(cls)
  </code></pre>
  <p>My logic was: if normal arguments are passed call <code>__init__()</code> with the given args, otherwise unpack the existing object and recall <code>__new__()</code> with the unpacked values.</p>
  <p>My issue is that <code>cls.__new__(cls, args[0].id_key, args[0].snapshot_key, args[0].version)</code> doesn't do what I thought it would do (call <code>__new__</code> recursively but with different args).</p>
  <p>Running this</p>
  <pre><code>schema= CacheSchema('a', 'b', 'c')
  schema2 = CacheSchema(schema)
  </code></pre>
  <p>raises</p>
  <pre><code>File &quot;D:/x/y/z/main.py&quot;, line 10, in &lt;module&gt;
      schema2 = CacheSchema(schema)
  TypeError: CacheSchema.__init__() missing 1 required positional argument: 'snapshot_key'
  </code></pre>