-
Notifications
You must be signed in to change notification settings - Fork 49
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
Refactor Work Files API to not shadow built-in open
#449
Conversation
- Change `open()` -> `open_file()` - Change `save()` -> `save_file()` to match with `open_file`.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice and simple !
I guess we dont want to and cant, maintain backwards compatibility? |
I don't get it. What problem does this solve? The original issue mentions..
What issues specifically? The "bad practice" part must be in reference to declaring open = "c:\my_file.txt"
with open(open) as f:
f.read()
# Having a bad time But surely, with a namespace this could not possibly be an issue? workfiles.open("c:\my_file.txt")
# Having a good time It's not an ideal name, but this is an API we're changing. APIs cannot break; like diamonds they are forever. Either keep both |
Might need to tag in the issue author @jasperges |
Isn't it bad practice to shadow built-ins anywhere as one might accidentally get bitten by it later? I think it's general bad practice. Anyway, I've solely set up this PR to correspond with the related issue and because I'm personally fine with it. Also, because it aligns the methods more with the others like Regarding it being an API. Sure. I understand the backwards compatibility notes. However, I am not sure if this ever was part of any front-facing API that was to be used outside of Avalon. It was only the design implemented for the work files tool. But looking at @tokejepsen his comment it seems the function have been referenced outside that scope too. (Or it was just a general question.) Feel free to do with it what fits best. :) Maybe @Jasperge has other notes to add. |
Ahh yeah, its not in the API so should be alright to rename. I'm guessing... |
Yeah, that's correct. But I think it would be a real (internal) bad practice if we need to use the built-in So I think we do need this be fixed, but also need to expose the Edit: Although it's not in the scope of the top level API, but it's on top of each host, so I think the backwards compatibility still need to be take cared. |
I thought of another issue why this PR is necessary. The |
I think it's actually safe, as long as you keep the namespace when you referencing, and the I did a quick test that has this structure: ./testopen
/__init__.py # Importing both following functions in the same scope
/builtin.py # Has a function that used the built-in `open`
/override.py # Has a function called `open` And they all worked safely. Unless I am testing in wrong direction ? |
That test does seem to cover the use-cases yes. It just means that no How about introducing the backwards compatibility only at the end of the # Backwards API compatibility
open = open_file
save = save_file I guess if anyone ever used it from "the host" then they wouldn't have accessed @davidlatwe you should be able to push changes directly into this branch for the PR if you want to implement backwards compatibility. Or let me know if you want me to add those lines and push it to the branch. |
It's not that serious; you can always |
That's what I have in mind, yes :D |
That option is checked. Hmm... Anyway, on it! |
@davidlatwe let me know if it's all good like this. 👍 |
Merge ! |
This resolves #407 so that the Work Files API does not shadow the built-in function
open
and refactors it toopen_file
. To keep a consistent API I've implemented the same change forsave
tosave_file
.What's changed?
Update the Work Files API:
open()
->open_file()
save()
->save_file()
to match withopen_file
.This is updated for the implemented hosts, the Work Files tool
README
that describes the API and the work files tool itself of course.