Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Core: Fix empty rule comparisons with subclasses #4201

Conversation

Mysteryem
Copy link
Contributor

What is this fixing or adding?

If a world uses a Location or Entrance subclass that overrides the item_rule/access_rule class attribute, then
spot.__class__.item_rule/spot.__class__.access_rule will get the overridden rule, which may not be an empty rule.

Uses of spot.__class__ have been replaced with getting the class attribute rule belonging to the Location or Entrance class.

How was this tested?

from BaseClasses import Location

class MyLocation(Location):
    pass

class MyLocationOverride(Location):
    item_rule = staticmethod(lambda item: False)

# Uses the empty rule, so should be True
my_loc = MyLocation(player=1)
# True
print(my_loc.item_rule is my_loc.__class__.item_rule)
# True
print(my_loc.item_rule is Location.item_rule)

# Overrides the empty rule, so should be False
my_loc_override = MyLocationOverride(player=1)
# True
print(my_loc_override.item_rule is my_loc_override.__class__.item_rule)
# False
print(my_loc_override.item_rule is Location.item_rule)

If a world uses a `Location` or `Entrance` subclass that overrides the
`item_rule`/`access_rule` class attribute, then
`spot.__class__.item_rule`/`spot.__class__.access_rule` will get the
overridden rule, which may not be an empty rule.

Uses of `spot.__class__` have been replaced with getting the class
attribute rule belonging to the `Location` or `Entrance` class.
@github-actions github-actions bot added affects: core Issues/PRs that touch core and may need additional validation. waiting-on: peer-review Issue/PR has not been reviewed by enough people yet. labels Nov 17, 2024
@Berserker66 Berserker66 merged commit 7eb1217 into ArchipelagoMW:main Nov 17, 2024
18 checks passed
AustinSumigray pushed a commit to AustinSumigray/Archipelago that referenced this pull request Jan 4, 2025
If a world uses a `Location` or `Entrance` subclass that overrides the
`item_rule`/`access_rule` class attribute, then
`spot.__class__.item_rule`/`spot.__class__.access_rule` will get the
overridden rule, which may not be an empty rule.

Uses of `spot.__class__` have been replaced with getting the class
attribute rule belonging to the `Location` or `Entrance` class.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
affects: core Issues/PRs that touch core and may need additional validation. waiting-on: peer-review Issue/PR has not been reviewed by enough people yet.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants