On 9/11/20 7:35 PM, Christopher Barker wrote:
---------------------------------------------
> But the real question is why staticmethod at all?
>
> And the answer is that there is very little use for staticmethod in
> Python [...]


On 9/11/20 7:28 PM, Greg Ewing wrote:
-------------------------------------
> IMO, static methods are a kludge only needed in languages that make
> classes do double duty as modules, and also can't have class methods
> because classes aren't first-class objects.

---------------------------------------------

I have a base class that holds the logic for converting from one data system to another. The module that holds this base class also imports several utility functions from other places.

The subclasses that hold the unique code occasionally have to overwrite/extend some of the base class methods, which means also needing to import the utility functions (the subclasses live in different files).

Rather than having to keep track of the various utility methods, including adding more imports if the base class uses more with new functionality, I just

      get_fis_table = staticmethod(fisData)
      get_xid_records = staticmethod(get_xid_records)

and then the subclasses can do

      blah = self.get_xid_records(...)

without worrying where `get_xid_records` came from.

Without `staticmethod` I would have to have a thin wrapper around those utility methods -- obviously not insurmountable, but annoying; and I really like that Python is not usually annoying.

--
~Ethan~
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/B7Q64WDU6EN235SWQX44CJ36XBUSJ3DH/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to