Skip to content
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

Handle missing keys better. #56

Open
thorwhalen opened this issue Mar 23, 2020 · 0 comments
Open

Handle missing keys better. #56

thorwhalen opened this issue Mar 23, 2020 · 0 comments

Comments

@thorwhalen
Copy link
Member

Several things came to my attention during the development of py2store, whose prior knowledge would have probably made me make different choices. There is a need to comb through the code and find where these better choices should be made.

(1) I didn't know about __missing__, which can probably be used advantageously.

(2) If a class has a __getitem__, but not a __iter__, it still uses __getitem__ on integers to possibly create iterable. This seems to be a not-so-great legacy from the past. But it's still there. I wouldn't want to create code that relies on it, but probably better to make sure we disable iteration when there's not an explicit __iter__, to avoid bugs or confusing behavior. I got one already when doing list(misc_objs) and got:

TypeError: expected str, bytes or os.PathLike object, not int

See:

(3) python docs says: Note for loops expect that an IndexError will be raised for illegal indexes to allow proper detection of the end of the sequence. Sometimes I decided to raise the "local" error (such as FileNotFound, etc.). This is also useful because the user IndexError alone would hide the real origin from the user or handling code. Perhaps the right error to raise should be a type('Specific', (FileNotFound, IndexError), {})?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant