problem with linked object and make local in python

my script has an option where you can choose if you want to link or append, but there is a bug.

this isn’t really a python problem, because it happens with append/link over the link/append menu in blender too.

how to reproduce my problem without python:

  1. link an object into your blend-file
  2. now make it local and choose “selected objects” and deselect all
  3. link the same object from the same file again
  4. now make the object local, but choose “objects + data”

i only want to have the second object full local.
the first object isn’t linked with the blend-file anymore. it is now linked with the second full local object. i don’t want this.
the first object should be linked with the blend-file and the second one should be local.

i tried it with the “append” code with python but i had problems with this

is there a way to solve this with python.

I’m not familiar with linking/append and I don’t know if this is pertinent but to link an object in python you do

new = obj.copy()

to full copy you add

new.data = obj.data.copy()