-
Notifications
You must be signed in to change notification settings - Fork 104
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
Add open(), read() and write() functions #34
Conversation
I re-read the discussion about I removed it in 12294be, but I will change the whole pull request to get fewer and more consistent commits. |
I combined the previous mess of commits into three fresh ones. I'm not sure if we agree on all points now ... @bastibe: we can take the changes to the tests from your branch |
I think we agree on the API for Implementation wise, have a look at a700fcf for simplifying Besides that, I am not satisfied with
What do you think about these points? |
I fail to see how The helper function The other helper function But this raises a more fundamental question: how defensive should we be when handling user input? I created a new pull request (#36) containing only the commits about the |
I think
At the very least, this should be factored in separate functions. In #37, I actually do not use the function at all. |
You're right that I'm still not clear on your position regarding how defensive we should be when checking user input. |
Sorry I was so inactive last week. I was sick. Anyway, about defensiveness: |
Now that we've merged #36, I rebased this PR onto the current master (0ca0eb3). I didn't add tests yet because I want to wait for #41. Also, I'd like to wait until we find an agreement on the discussions in #33. I quickly checked, though, by replacing the methods with the respective functions in the tests (at least in those that don't involve
Yes, we agreed.
I put it there to avoid the slightly ugly Another, probably not very convincing argument would be that if only the low-level stuff is used, the import doesn't have to be done at all.
This wouldn't be cleaner nor simpler. It would be nice to manipulate the signature automatically based on the method's signatures, but AFAIK this in only possible with severe hackery involving But as soon as we have proper docstrings (#27), I think the need for that will go away.
Oh no, please let's not! It would be crazy to unnecessarily limit the features of the functions. All parameters as they are implemented in this PR make perfect sense.
Sure, there still remain use cases where the methods have to be used. But I guess a huge percentage of users will never have to call any of the methods directly. And that's a good thing! It also makes for a much cleaner documentation. All the
Obviously it's redundant in the sense that it's literally But it's just so much more Pythonic! If you want to open a text file in Python, you use Therefore, I think it perfectly makes sense to prefer I tried to make this point already (https://github.com/bastibe/PySoundFile/pull/14#issuecomment-36464595), sorry for the repetition. |
I thought a bit about the I still think spelling out all arguments would mean an annoying amount of duplication and it would make the whole thing definitely harder to maintain. Another benefit would be that we could avoid the whole |
... instead of using *args and **kwargs.
Yes, I think this definitely makes the functions much easier to understand. However, I disagree with 49f0e23. I think the documentation should be placed where the functionality is actually implemented, not in some wrapper function. Ideally, the docstring information really should be available to both the functions and methods. Is there any way we can programmatically append the docstring from the method to the function? |
Re-use constructor docstring for open()
It's no problem to re-use the init-docstring for I'm not sure if this is also a good idea for Also, I don't know if we can still separate the two parts nicely once we switch to NumPy-style docstrings (#27). |
I am uncomfortable with not documenting a function/method. If I look up the documentation for a function/method (most likely through some functionality of my text editor), I want to see the documentation. A referral to some other place is nice, but my text editor can't parse that. I'd rather have duplicate documentation than no documentation. Right now I get no documentation at all on Frankly, I'd prefer to have a full copy of the docstring in both |
If you don't see any documentation for
If you insist I can duplicate the text which is valid for both method and function, I don't like it but I don't want to get too religious about that, either. There are other questions where if have a much stronger opinion. But I would like to point out that, as far as I've seen, it is common practice in NumPy to refer somewhere else for documentation. E.g.
See also http://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.reshape.html#numpy.ndarray.reshape vs Of course in our case it's not really an equivalent function, but it's still a similar situation. |
The main issue I see here is that we will probably have a lot of users who will use either the functions or the methods, but not both. It might be confusing for them to have full documentation available for one but not the other. I feel that if we were to skip the documentation on one of In the end, I would vote for having full documentation everywhere. I guess there is some middle ground though. In particular, I would probably be fine to simplify the function documentation a bit and defer some rarely-used details to the methods. This would make simple usage simpler and power-users more powerful. We are in for a documentation rewrite anyway though, so we can easily defer this to a later time. |
OK, that sounds reasonable. I duplicated the documentation in Can we merge now? |
Add open(), read() and write() functions
This is the combination of a few commits from #18.
See also #14.