Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Naming a method which modifies data in place in Python

from dataclasses import dataclass
from utils import gen_x

@dataclass
class Data:
    x: str
    
    def foo():
        self.x = gen_x()

d = Data('bar')
d.foo()

I need to modify x in place from usability reasons, but I don’t know how to clearly indicate that in name of method which performs that modification (named here: foo).

Rejected names:

  • generate_x – means, that x is generated and returned, not substituted in instance
  • substitute_x – better than previous, but looks strange

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

update_x or replace_x – These two names would be better if you want to modify the x attribute in place

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading