-2

I created a list of elements and I want to update one of the list elements

This is the call to the update method:

companies_list = self.create_list("xpath", self.txt_company_name)
self.update_elem(companies_list[0], company1_name)

And this is the update method:

def update_elem(self, elem, text):
    elem.send_keys(text)

At the method I'm getting warning "Make function from method" and a suggestion "Method 'update_elem' may be 'static'"

What is the correct way to update the list element without getting warnings?

MrBean Bremen
  • 14,916
  • 3
  • 26
  • 46
Lior p
  • 45
  • 6
  • That method could indeed be static, or just a function, because it _doesn't use `self`_. Or just inline it, it's only one line anyway. – jonrsharpe Jan 10 '22 at 10:03
  • You don't use `self` in the method body so it's a function. Use `@staticmethod` and remove self to fix the warning. – mx0 Jan 10 '22 at 10:05

1 Answers1

0

Assuming you're using Pycharm, it thinks you wanted to declare the 'update_elem' as static as it does not change in the body of the method the class instance.

take a look at this answer, you basically need to add @staticmethod decorator or have 'update_elem' change the instance of the class.

pugi
  • 323
  • 1
  • 12
  • 1
    Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jan 10 '22 at 10:19
  • What further details do i need to add? – Lior p Jan 10 '22 at 13:34
  • 1
    @Liorp either add `@staticmethod` decorator before `update_elem` method or have `update_elem` method change an attribute of the class - something like `self.elem.send_keys(text)` or `self.elem = elem.send_keys(text)` – pugi Jan 10 '22 at 14:21