python-sc2 icon indicating copy to clipboard operation
python-sc2 copied to clipboard

make already_pending_upgrade safe for all UpgradeId

Open DuncanDHall opened this issue 2 years ago • 1 comments

In case of iteration over UpgradeId to poll current upgrades

DuncanDHall avatar Apr 17 '22 01:04 DuncanDHall

Can you give me an example of in which situation it currently fails?

Edit: It seems in the context of

pending_upgrades = [upgrade for upgrade in UpgradeId if self.already_pending_upgrade(upgrade) != 0]

it fails. But in my opinion this is bad practice because it loops over upgrades that are no in the game. So a better solution would be to pre-filter UpgradeIds that are not in the game at all. If you want to iterate over UpgradeIds like that, I'd suggest using the dict in https://github.com/BurnySc2/python-sc2/blob/develop/sc2/dicts/upgrade_researched_from.py

BurnySc2 avatar Apr 23 '22 12:04 BurnySc2

From a conversation I had in discord, it seems this PR aims to return 0 whenever an UpgradeId was given as argument, that is not in the game (but in the enum list). However this seems like a rare use case to me and seems bad practice in general. Closing the PR because of this

BurnySc2 avatar Dec 24 '22 17:12 BurnySc2