Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactored by Sourcery AI #188

Merged
merged 2 commits into from
Jun 19, 2023
Merged

Refactored by Sourcery AI #188

merged 2 commits into from
Jun 19, 2023

Conversation

LopeKinz
Copy link
Contributor

4 File changed with 9 Additions and 10 deletions

Sourcery AI and others added 2 commits June 19, 2023 06:45
@@ -39,7 +39,7 @@ def fassistant(self, msg):

def next(self, messages: list[dict[str, str]], prompt=None):
if prompt:
messages = messages + [{"role": "user", "content": prompt}]
messages += [{"role": "user", "content": prompt}]
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extending a list modifies the argument in python no?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe both lines do exactly the same.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes they do.

Copy link

@tmpolaczyk tmpolaczyk Jun 19, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They don't, += modifies the variable for the caller, the old code creates a new variable. I was testing this out while you merged lol:

def foo1(messages):
    messages += ["role"]

def foo2(messages):
    messages = messages + ["role"]

m1 = ["m1"]
foo1(m1)
print(m1)
m2 = ["m2"]
foo2(m2)
print(m2)

This prints

['m1', 'role']
['m2']

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what python version?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Call them the other way around:

def foo1(messages):
    messages += ["role"]

def foo2(messages):
    messages = messages + ["role"]

m2 = ["m2"]
foo2(m2)
print(m2)

m1 = ["m1"]
foo1(m1)
print(m1)

this prints:

['m2']
['m1', 'role']

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just opened a pr without +=

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, copied the wrong output, yeah it was:

['m2']
['m1', 'role']

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to clarify

in foo1 we are modifying the messages variable given as parameter

in foo2 we are creating a new list and the original messages remains unchanged

In the actual code we are returning messages so it would be like adding a return in foo2 if you want to compare.

@AntonOsika
Copy link
Owner

Extending a list modifies the argument in python no?

Otherwise looks great and I’m happy to merge

@patillacode patillacode merged commit ac958df into AntonOsika:main Jun 19, 2023
70ziko pushed a commit to 70ziko/gpt-engineer that referenced this pull request Oct 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants