Пример:
class PackageInfo:
def depends_on(self, package: PackageInfo):
result = self.required_package_list.index(package.package_name) > -1
return result
Python ругается на объявление - package: PackageInfo
Имя в кавычки возьмите.
def depends_on(self, package: 'PackageInfo')
Прочитать об этом можно тут: forward-reference.
Попробуйте так:
class PackageInfo:
def __init__(self):
super().__init__()
self.package_name = '1'
self.required_package_list = ['1', '2', '3']
# def depends_on(self, package: PackageInfo):
def depends_on(self):
# result = self.required_package_list.index(self.package_name) > -1
result = self.package_name in self.required_package_list
return result
packageInfo = PackageInfo()
result = packageInfo.depends_on()
print(f'\nresult = {result}')
packageInfo.package_name = '22'
result = packageInfo.depends_on()
print(f'\nresult 22 = {result}')
packageInfo.package_name = '2'
result = packageInfo.depends_on()
print(f'\nresult 2 = {result}')