-
Notifications
You must be signed in to change notification settings - Fork 2k
Closed
Labels
bugSomething isn't workingSomething isn't workingfixesRelated to suggested fixes for violationsRelated to suggested fixes for violations
Description
b = 1
def f(a): # Use `operator.itemgetter(b)` instead of defining a function
return a[b]
b = 2
f([1, 2, 3]) # 3playground
but if we follow that direction:
b = 1
f = operator.itemgetter(b)
b = 2
f([1, 2, 3]) # 2Original issue:
class A:
def __init__(self):
self.foo = 1
@property
def f(self) -> object: # Use `operator.itemgetter(self.foo)` instead of defining a function
return self[self.foo]This function references an input in the value position, making it impossible to rewrite as an attribute
class A:
def __init__(self):
self.foo = 1
f = property(operator.itemgetter(self.foo))And if we define it in the __init__ then it would always use the intial value of foo:
class A:
def __init__(self):
self.foo = 1
self.f = property(operator.itemgetter(self.foo))Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't workingfixesRelated to suggested fixes for violationsRelated to suggested fixes for violations