tl;dr: some changes I've made to a package don't appear, depending on where I call them from
To simplify, this is the minimal core of what happens:
paths:
/project/A/__init__.py /project/A/A.py /project/B/__init__.py /project/B/B.py
old code:
A.py:
class A:
def __init__(self):
self.oldAttr = 2
def getOldAttr(self):
return self.oldAttr
B.py:
import A
class B:
def __init__(self):
self.a = A.A()
print("old attr: ", self.a.oldAttr)
print("old attr: ", self.a.getOldAttr())
here everything is fine and dandy, I have access oldAttr anyway I want. However, I wanted to add newAttr to A but I couldn't access it from b so I made the following changes to see whats wrong:
new code:
A.py:
print ('loading A')
class A:
def __init__(self):
self.newAttr = 1
print('defined new attr', self.newAttr)
self.oldAttr = 2
def getNewAttr(self):
print(dir(self))
return self.newAttr
def getOldAttr(self):
print(dir(self))
print("new attr: ", self.newAttr)
return self.oldAttr
B.py:
import A
import pathlib
import sys
from importlib import reload
path_to_A = str(pathlib.Path(__file__).parent.parent.absolute())+'/A'
if path_to_A not in sys.path:
sys.path.append(path_to_A)
reload(A)
class B:
def __init__(self):
self.a = A.A()
print(dir(self.a))
print("old attr: ", self.a.getOldAttr())
print("new attr: ", self.a.getNewAttr())
print("new attr: ", self.a.newAttr)
The result? the attribute list called from B or from getNewAttr contains getNewAttr but does not contain newAttr so calling self.a.newAttr is an error or self.newAttr in getNewAttr, but it exists in the attribute list in getOldAttr and in init of A where it can print it fine.
I am using python 3.10.4 I have ubuntu 22.04
I deleted the cache, restarted the computer, reloaded the imports, checked that it reloads using prints, tested the attribute list in differing locations, and hit wall when I saw it differing so wildly
I tried debugging using pdb, in A newAttr is created, but when I step out, self.a.newAttr no longer exists. (and it does exist again later when in getOldAttr, but again does not exist in getNewAttr)
Any help would be appreciated