Private key to WIF compressed: which one is correct? This is how we can find the WIF from a private key:

private_key = '000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f'
decoded_private_key = bitcoin.decode_privkey(private_key, 'hex')
wif = bitcoin.encode_privkey(decoded_private_key, 'wif')
# 5HpHgWkLaovGWySEFpng1XQ6pdG1TzNWR7SrETvfTRVdKHNXZh8


But how to get the WIF compressed?

Should I do:

private_key = '000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f'
compressed_private_key = private_key + '01'
wifcomp1 = bitcoin.encode_privkey(bitcoin.decode_privkey(private_key, 'hex'), \
             'wif_compressed')
# KwDidQJHSE67VJ6MWRvbBKAxhD3F48DvqRT6JRqrjd7MHLBjGF7V


or 

wifcomp2 = bitcoin.encode_privkey(bitcoin.decode_privkey(compressed_private_key, 'hex'), \ 
            'wif_compressed')
# KwFfpDsaF7yxCELuyrH9gP5XL7TAt5b9HPWC1xCQbmrxfFzfMakg


It seems that #1 is correct and not #2.



Also it seems that:


the non-compressed WIF, imported in Electrum, produces finally a non-compressed Base58 address, 
the compressed WIF, imported in Electrum, produces finally a compressed Base58 address


which seems obvious. But I'd like to be sure that compression of WIF and compression of addresses at the end is really linked.

Can we conclude that the use of a compressed or non-compressed WIF (both encoding the same private key) will determine, when importing them in Electrum, if the public-key (and thus the address eventually) will finally be compressed or non-compressed?
It seems that #1 is correct and not #2.


Yes, #1 is correct. The encoder will add the 01 flag byte to the end of the private key for you. By doing that manually in #2, you will result in the private key having an additional byte which is incorrect.