New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

getAllEntries returns empty string instead of None. #233

Closed
mpmc opened this Issue Aug 31, 2017 · 2 comments

Comments

Projects
None yet
2 participants
@mpmc
Contributor

mpmc commented Aug 31, 2017

I'm using getAllEntries, these values are always ints (port entries). If the entry is empty, an empty string is returned which is fine for most cases but if you then try to convert to an int you get a value error.

ValueError: invalid literal for int() with base 10: ''

This is to be expected because it's a blank string, and not a numeric value in string form. the same also happens for None values.

I think in the cases where there is no value it might be best not to include them in the dictionary instead of blank strings?

@jarvisteach

This comment has been minimized.

Owner

jarvisteach commented Sep 1, 2017

I'm not sure that's the right approach. I think .getAllEntries() should return ALL the entries, regardless of their contents, and leave it to the user to process them accordingly. If you're expecting numbers, then you should check for/handle missing/invalid numbers.

If you're using .addNumericEntry() then they should return 0 if there's no value - if they're not, then that's a bug.

If they're standard entries, and the user didn't type anything, then I would expect an empty string - as that's the current value of the entry.

There's a case to say numeric entries should return None if they're empty....

@mpmc

This comment has been minimized.

Contributor

mpmc commented Sep 1, 2017

There's a case to say numeric entries should return None if they're empty....

That would be fantastic !

I worked around it, and get value checking without using lots of If lines by doing this.

        udp = 8086
        tcp = 8087
        timeout = 5   
        values = self.getAllEntries()
        try:
            udp = int(values[self.lang('main_win_adv_udp_title')])
            tcp = int(values[self.lang('main_win_adv_tcp_title')])
            timeout = int(values[self.lang('main_win_adv_to_title')])
        except ValueError:
            pass

Which works (almost) very nicely as the defaults are used on error, even if the user enters non-numeric values, it also sorts out empty strings. Only issue is all defaults are used if the previous line fails, which if I'm honest I have no problems with.

@jarvisteach jarvisteach modified the milestone: 0.09 Sep 5, 2017

jarvisteach added a commit that referenced this issue Oct 14, 2017

@jarvisteach jarvisteach modified the milestones: 0.90, 0.82 Oct 24, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment