NebulousLabs / python-skynet

Library for integrating Skynet with Python applications
MIT License
19 stars 11 forks source link

Ability to set request timeout, made opts parameters optional #20

Closed DaWe35 closed 4 years ago

DaWe35 commented 4 years ago

This PR includes two backward-compatible updates.

Complete example for upload (source):

opts = type('obj', (object,), {
    'portal_url': portal,
    'timeout': 20
})
try:
    try:
        skylink = Skynet.upload_file('file.txt', opts)
        print(skylink)
    except TimeoutError as e:
        # timed out

except Exception as e:
    # other error
marcinja commented 4 years ago

Looks good to me. Just needs the changes m-cat already mentioned.

DaWe35 commented 4 years ago

@m-cat 1. What about making default_upload_options and default_download_options able to handle deficient opts? I mean do we really need the fill_with... functions?

  1. agree
mrcnski commented 4 years ago

@m-cat 1. What about making default_upload_options and default_download_options able to handle deficient opts? I mean do we really need the fill_with... functions?

Interesting idea. In my opinion the default_ functions should just return the default opts as before. I don't see the reason for a user to pass in a deficient opts, the upload and download methods will just fill in the missing opts anyway. I would keep the default_ functions simple, behaving the same way as in the other SDKs, while we make the fill_with functions private. This way we don't complicate the API at all and still have elegant option-filling internally.

mrcnski commented 4 years ago

@DaWe35 Since these are static methods there is no class instance, you need to do Skynet.fill_with_default_upload_options()

mrcnski commented 4 years ago

Okay, I've seen you've done that. Looks great to me! Will give it one more look-through.