That’s what the newly enacted Cal. Penal Code § 25135, just signed by Gov. Brown, would do (on pain of criminal punishment) [note UPDATE below]:
A person who is 18 years of age or older, and who is the owner, lessee, renter, or other legal occupant of a residence, who owns a firearm and who knows or has reason to know that another person also residing therein is prohibited by state or federal law from possessing, receiving, owning, or purchasing a firearm shall not keep in that residence any firearm that he or she owns unless one of the following applies:
(1) The firearm is maintained within a locked container.
(2) The firearm is disabled by a firearm safety device.
(3) The firearm is maintained within a locked gun safe.
(4) The firearm is maintained within a locked trunk.
(5) The firearm is locked with a locking device as described in Section 16860, which has rendered the firearm inoperable.
(6) The firearm is carried on the person or within close enough proximity thereto that the individual can readily retrieve and use the firearm as if carried on the person.
Federal law, 18 U.S.C. § 922(d)(5)(B), (g)(5)(B), provides that foreigners who are lawfully here under a nonimmigrant visa — which can include foreign college or graduate students, people who are lawfully working for a business but don’t have an unrestricted green card, and more — are generally barred from possessing, receiving, owning, or buying a firearm. So if someone living in your residence, whether as a housemate, a lover, or what have you, is a foreigner, you must keep your guns locked up, even if the foreigner is a perfectly responsible adult.
To be sure, many gun owners keep their guns locked up in any event, but some people who live in dangerous parts of town may figure that having the guns immediately ready is important to their self-defense (and to their ability to defend their family members), and that this benefit outweighs whatever risk is posed by having the guns be unlocked. That may be a perfectly reasonable decision for people to make, especially if they don’t have small children around. But California law would prevent them from making this decision.
The law of course also requires people to keep their guns locked up if a housemate or family member has a felony conviction — even a nonviolent felony, or one many decades in the past. That itself is too much of an intrusion on the self-defense rights of law-abiding people, it seems to me. (For more on that, see this post, and this follow-up, which notes the reversal of the case mentioned in the first post.) But the applicability of the law to people who live with foreigners seems to me to be even harder to justify.
UPDATE: I at first didn’t discuss exception (6), “[t]he firearm is carried on the person or within close enough proximity thereto that the individual can readily retrieve and use the firearm as if carried on the person,” because it seemed to me transparently inadequate for the ordinary lives of most gun owners. If you don’t keep the gun locked up, and rely on this, that means you have to be constantly carrying the gun from room to room in your home, though with the option of taking it out as you enter a room, if you’ll pick it up when you leave the room.
You’re in bed with the gun in the nightstand, and you need to go to the bathroom? You’ll have to either lock up the gun, go to the bathroom, and then unlock the gun, or carry the gun with you to the bathroom. Want to go to the kitchen for a midnight snack? Someone’s at the door (under circumstances where you know everything is perfectly safe)? The phone is ringing and you don’t have an extension in the room? Same story. Have to go outside to get something from your car that’s parked on the street, or talk to a neighbor? Lock up the gun, since you can’t carry it with you outside (unless you have a concealed carry permit, which is very hard to get in California), then unlock it when you return. Forget to lock the gun or carry it with you? You’re a criminal.
I suppose some people who live in extraordinarily dangerous circumstances — not just the circumstances that lead people to keep a loaded gun unlocked in their nightstands, but far more dangerous circumstances than that — might routinely carry the gun on their persons everywhere, including to the bathroom. Most people, I suspect, would find this sort of lifestyle so inconvenient and so likely to lead to a mistake that turns them into criminals that they would conclude that they need to keep their guns locked up. And I can’t imagine that the drafters expected anything else; subsection (6), I suspect, was understood as applicable to emergency situations (e.g., when you’re anticipating the likelihood of having to use the gun right away) or possible to police officers or security guards who are coming to or from work. The point of the law, it seems to me, is precisely to have people keep their guns locked up nearly all the time if there is a person living with them who isn’t allowed to own a gun.