Skip to content

Commit

Permalink
Dyn methods: Factor out instance var
Browse files Browse the repository at this point in the history
This small refactoring prepares for a later commit that will switch to
binding the methods to the class instead of to the instance. The
instance attribute `prog` will not be available then anymore, because
no instance exists yet at the time the class is created. Therefore, the
reference is now replaced by the string `'dot'`.

Note that this does not actually change the default value at all. It
always got fixed to the value of `prog` at the time of function
definition, which was always `'dot'`, as can be seen from line 1713.
The default value already never changed along with the instance
attribute value anymore after function definition.

Side note:

- One could argue that `None` would make a better default value here.
  However, changing that now would be changing the external behavior of
  the methods themselves, while this series aims to change the way in
  which they are created with minimal external effects. I plan to
  propose a switch to `None` together with other changes to
  `create_*`/`write_*` in another series, though.

(This commit is part of a series of changes in how the `get_*`,
`set_*`, `create_*` and `write_*` methods are dynamically created.)
  • Loading branch information
peternowee committed Oct 26, 2020
1 parent c8b008b commit 3bd7797
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions pydot.py
Original file line number Diff line number Diff line change
Expand Up @@ -1717,7 +1717,7 @@ def __init__(self, *argsl, **argsd):
# of output in any of the supported formats.
for frmt in self.formats:
def new_method(
f=frmt, prog=self.prog,
f=frmt, prog='dot',
encoding=None):
"""Refer to docstring of method `create`."""
return self.create(
Expand All @@ -1727,7 +1727,7 @@ def new_method(

for frmt in self.formats+['raw']:
def new_method(
path, f=frmt, prog=self.prog,
path, f=frmt, prog='dot',
encoding=None):
"""Refer to docstring of method `write.`"""
self.write(
Expand Down

0 comments on commit 3bd7797

Please sign in to comment.