Created
December 10, 2019 07:51
-
-
Save a-recknagel/2a01466199470ba61874f76e0fa4ea8b to your computer and use it in GitHub Desktop.
getting around access restrictions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Dog: | |
__slots__ = ["foo"] | |
def __setattr__(self, name, value): | |
raise TypeError("(•ˋ _ ˊ•) no touch, only throw.") | |
d = Dog() | |
# your one line of code here | |
assert type(d) is Dog | |
print(d.foo) # "take stick" | |
# solutions | |
object.__setattr__(d, "foo", "take stick") | |
Dog.foo = "take stick" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment