[Tutor] Trying to understand how object re-instantiation gets propagated
dn
PyTutor at DancesWithMice.info
Wed Feb 17 15:50:19 EST 2021
On 18/02/2021 00.43, Dimitar Ivanov wrote:
...
> My JIRA issue class (shown below) retrieves the values from a JIRA server
> and saves them as instance variables. To avoid outdated information when I
> update a value on the JIRA server, I made a small function that retrieves
> the JIRA issue from the server again and re-instantiates a new object of my
> class:
...
> So, my question is - how does this happen? How does the interpreter
know of
> the new object and automatically assigns it to my_issue?
Why "a new object"?
Why think in terms of two objects?
1 Have faith:
my_issue is created with data from Jira. The assignee is changed by the
code. The Jira db is updated. The local data and the (remote) db are now
identical - assuming there was no exception during the update.
2 Be sure:
There appears to be no need to hold the pre-update JiraIssue object as
well as its assignee-updated object. After the update is sent to Jira,
consider ignoring/deleting that object (from the code), and
instantiating an entirely new/different JiraIssue object (rather than
reload-ing).
> def main():
> jira_issue = jira_connection.issue("ISSUE-1") # Retrieving the issue
> from the JIRA server
> my_issue = JiraIssue(jira_issue)
...
> my_issue.reload()
...
> def reload(self):
> jira_issue = jira_connection.issue(self.key) # Retrieving the issue
Why is the jira_connection call outside of the JiraIssue object, and not
part of its __init__() - given that the same step is part of reload()?
(or vice-versa: why is reload() a method and not external...)
> class JiraIssue:
> def __init__(self, jira_issue):
> self.key = issue.key
> self.assignee = issue.fields.assignee
Is this working-code?
Parameter is "jira_issue" but method's assignments refer to an "issue"
object.
--
Regards,
=dn
More information about the Tutor
mailing list