More correctly, a pinhole has an infinte (or close to it) depth of focus and depth of field. (The two are different.) This is why the wazzit thingie works.
I used to mount an extension tube with a piece of bronze sheet with a properly-cut pinhole in it to achieve extreme depth of focus in some "pattern shots," like a row of fenceposts, and for some macro-photography.
Pinhole cameras are interesting things. There is a whole technology surrounding them. A proper pinhole aperture has to have sharp edges, so you first drill the hole, then cut a taper into it so the actual hole has sharp edges.
There's a compromise involved, though. With smaller and smaller pinholes, you soon run into diffraction effects, which tend to drop the resolution. There are formulae to calculate the optimum pinhole diameter for a particular use. The iimage also gets dimmer with a smaller pinhole.
This is a pure fun "pinhole" thing to do which illustrates a lot about pinholes and the way the wazzit works:
One thing that impressed the heck out of my kids when they were younger was to close off a window (using cardboard, aluminum foil, whatever) in a room with a white wall opposite the window. With about a 1/2" hole in the cardboard (or whatever), you could see an upside-down full color image on the wall of everything happening outside when the lights are turned off. Cars moving by, people picking their noses, etc. The bigger the hole, the brighter the image, but also the more blurry.
It is quite a dramatic effect, especially to kids --has the flavor of a "miracle," sort of.
You will note that no matter how far away the object (car, nose-picker) is, it will be in focus (depth of field). And no matter how far away the wall is, it will still be in focus (depth of focus).
It's called a Camera Obscura in case you want to look it up.
----------
BTW, the "diopter power" of a lens is 1 meter divided by the focal length in meters. That is, a lens with a focal length of 1/2 a meter is a 2 diopter lens.
The beauty of using diopters is that the combined power of two (or more) lenses is simply the sum of the diopters. A 2-diopter lens plus a 3-diopter lens will be the equivalent of a 5-diopter lens.
(But when you go to the drugstore for a pair of inexpensive reading glasses, they usually drop the decimals. A " + 275 " strength pair of glasses are actually 2.75 diopters focal length.)