scripts: Adopt __get__ binding for write/writeln methods

This actually binds our custom write/writeln functions as methods to the
file object:

  def writeln(self, s=''):
      self.write(s)
      self.write('\n')
  f.writeln = writeln.__get__(f)

This doesn't really gain us anything, but is a bit more correct and may
be safer if other code messes with the file's internals.
This commit is contained in:
Christopher Haster
2025-06-27 12:42:18 -05:00
parent 8b6e51d54e
commit 8cc81aef7d
11 changed files with 62 additions and 60 deletions

View File

@@ -951,11 +951,11 @@ def main_(ring, paths, *,
label=False,
no_label=False,
**args):
# give ring an writeln function
def writeln(s=''):
ring.write(s)
ring.write('\n')
ring.writeln = writeln
# give ring a writeln function
def writeln(self, s=''):
self.write(s)
self.write('\n')
ring.writeln = writeln.__get__(ring)
# figure out what color should be
if color == 'auto':