Skip to content

Instantly share code, notes, and snippets.

@a-recknagel
Created December 10, 2019 07:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save a-recknagel/2a01466199470ba61874f76e0fa4ea8b to your computer and use it in GitHub Desktop.
Save a-recknagel/2a01466199470ba61874f76e0fa4ea8b to your computer and use it in GitHub Desktop.
getting around access restrictions
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