Steven D'Aprano <steve+comp.lang.pyt...@pearwood.info>: > On Sun, 02 Mar 2014 11:35:43 +0200, Marko Rauhamaa wrote: >> Now, what kinds of object are those constants? We are not supposed to >> know or care. > > Incorrect. We are supposed to know and care.
Then, the documentation is seriously flawed. It gives no hint whatsoever on the nature of those objects. > os.posix is exactly the sort of library I mentioned earlier when I > said sometimes you're constrained by compatibility with some other > system. In this case, the os module is explicitly designed to be > compatible with the POSIX interface, which is defined to use certain > integer values as flags. This is not an implementation choice which > implementers can change at will, it is part of the interface. The values of those Python constants don't need to have any relationship with those of the underlying operating system. > Python does not guarantee that there is only a single 1 instance. Nobody has ever argued such a thing. I certainly haven't. However, nothing in the API spec gives you the right to call the function with an integer. > If you want to test whether a value is os.POSIX_FADV_RANDOM, the right > way is to compare that value for equality with os.POSIX_FADV_RANDOM, > not identity. That might well be true but is not explicitly or implicitly specified in the documentation. (The os.SEEK_* constants are explicitly defined.) >> Since, for all I know, os.POSIX_FAVD_RANDOM might return a random value >> for __eq__(). > > For all *you* know, perhaps, but since os.posix_fadvise is a thin > wrapper around the POSIX C function fadvise, and that is documented as > expecting ints for the advice parameter, that cannot be the case. A pretty serious documentation flaw, then. Misleading even. I take it from the documentation that you *must* use the given constant objects and not some improvised integers. > That the os module is a thin wrapper around os- specific services may > not be explicitly stated, but it is nevertheless true. The example was given for illustration purposes; any criticism against the accuracy of the documentation is a sideshow. Marko -- https://mail.python.org/mailman/listinfo/python-list