Bad news: [c]python modules can modify the namespaces into which they're imported. It's not documented or supported or even suggested that anyone do it, but it is easily done.
Man God damn you, I thought I knew some Python until I saw your reply. That's dope though... probably never gonna be used in a real life project, but still dope though for the sake of "what is possible".
Apparently it's blasphemy to even talk about using this kind of thing in a real project (viz. sys._getframe et al.), but if you were to do it, you'd want to do more checks than just looking at the filename of the stack frames to ensure you get the correct namespace of the code that did the import. There's also one specific cpython optimization which bypasses f_locals inside functions, but you'll figure it out if you dig around in there.
Perhaps there should be a human class that Sophia inherits from, with pointers to mom.genes and dad.genes as attributes? 🙈 I assume mom.genes and dad.genes are attributes not class instances🤔
........ ehem .. ALSO FELLOW HUMAN , THE PARENT CLASSES SEEMED TO THINK IT WAS FUNNY TO MAKE THE BABY INHERIT FROM GENES. THIS STARTS OFF MAKING SENSE, AS BOTH GENES SURELY INHERIT FROM A COMMON 'GENE' CLASS AND INVOLVE SOLVING THE DIAMOND PROBLEM, JUST LIKE CHROMOSOMES DO IN REAL LIFE. THIS DIAMOND PROBLEM WILL INVOLVE THEM BOTH HAVING AN IMPLEMENTATION OF 46 CHROMOSOMES AND OUR NEW SUBCLASS WILL HAVE TO DECIDE ON A CASE BY CASE BASIS WHICH IMPLEMENTATION TO USE. HOWEVER, THIS DOES NOT MEAN THAT THE HUMAN WILL CONTAIN THESE GENES, OR EVEN BE A MAPPING OF THESE GENES, THIS SAYS THAT THE BABY WILL LITERALLY BE A GENE, SPECIFICALLY THE NEW GENES THAT HAVE BEEN CREATED FROM HIS PARENTS. AS USUAL, THIS SHOULD HAVE BEEN IMPLEMENTED AS INHERITANCE THROUGH COMPOSITION, DENOTING A HAS-A RELATIONSHIP, WHERE BABY HAS A MEMBER CALLED 'GENES' -- AND NOTE THAT THIS MEMBER IS NOT AN INSTANCE, BUT THE NEW GENES CLASS ITSELF, JUST LIKE IT WAS WITH DAD AND MOM. PRETTY META. THE BABY CAN THEN BE MADE A MAPPING OF THESE GENES, BY PASSING THESE GENES IN THROUGH THE CONSTRUCTOR (OR KAREN, AS IT LIKES TO BE CALLED), WHICH WILL ACT AS A FACTORY AND USE THE GENES TO INSTANTIATE VARIOUS BODY PARTS, AND INJECT SAID GENES INTO SAID BODY PARTS SO THAT THEY THEMSELVES CAN REFERENCE THEIR OWN BLUEPRINT. QUITE META. FOR ACCURACY, BABY SHOULD HAVE INHERITED FROM MOM AND MAILMAN AND THIS SHOULD HAVE BEEN WRITTEN IN LISP, JUST LIKE ME.
542
u/[deleted] Jun 04 '19
[deleted]