Skip to content

Add __copy__, __deepcopy__ to URL. Fixes: #7400#7401

Closed
rec wants to merge 1 commit intosqlalchemy:mainfrom
rec:copy
Closed

Add __copy__, __deepcopy__ to URL. Fixes: #7400#7401
rec wants to merge 1 commit intosqlalchemy:mainfrom
rec:copy

Conversation

@rec
Copy link
Copy Markdown
Contributor

@rec rec commented Dec 5, 2021

Description

Allows copy.copy and copy.deepcopy to be used on instances of sqlalchemy.engine.url.URL.

Checklist

This pull request is:

  • A short code fix
    • please include the issue number, and create an issue if none exists, which
      must include a complete example of the issue. one line code fixes without an
      issue and demonstration will not be accepted.
    • Please include: Fixes: #<issue number> in the commit message
    • please include tests. one line code fixes without tests will not be accepted.

@zzzeek zzzeek requested a review from sqla-tester December 5, 2021 18:27
Copy link
Copy Markdown
Collaborator

@sqla-tester sqla-tester left a comment

Choose a reason for hiding this comment

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

OK, this is sqla-tester setting up my work on behalf of zzzeek to try to get revision a2c1b89 of this pull request into gerrit so we can run tests and reviews and stuff

@sqla-tester
Copy link
Copy Markdown
Collaborator

New Gerrit review created for change a2c1b89: https://gerrit.sqlalchemy.org/c/sqlalchemy/sqlalchemy/+/3352

Copy link
Copy Markdown
Member

@zzzeek zzzeek left a comment

Choose a reason for hiding this comment

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

great, thanks.

I want to cherry-pick this to 1.4, add a changelog, and also update it a bit, which I can do on this end very easily from the Gerrit side.

is_false(url1 == url3)

def test_warnings(self):
assert_raises(
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

we should have tests for this elsewhere so I will take this part out.

url1 = url.URL.create("dbtype")
url2 = copy.copy(url1)
url3 = copy.deepcopy(url2)
is_true(url1 == url2)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

we have a fixture eq_() for this, eq_(url1, url2). it's not any better or worse we just try to be consistent.

)

def __deepcopy__(self, memo):
return self.__copy__()
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

self.query is a dict so we likely need to deepcopy that also

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

though if it's a dict of str->str in all cases, then not. let me check that

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Ooops!

It still needs to be copied, though, you don't want the same mutable dict in two entries.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

it's fine the way it is, the dict is immutable (special SQLAlhcemy class) and the contents are all strings / tuples of strings / tuples . fully immutable contents as well. thanks !

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Immutable dicts, great idea!

Thanks again for an excellent package, and I hope the rest of your weekend is fantastic.

@sqla-tester
Copy link
Copy Markdown
Collaborator

Gerrit review https://gerrit.sqlalchemy.org/c/sqlalchemy/sqlalchemy/+/3352 has been merged. Congratulations! :)

@sqla-tester
Copy link
Copy Markdown
Collaborator

Gerrit review https://gerrit.sqlalchemy.org/c/sqlalchemy/sqlalchemy/+/3353 has been merged. Congratulations! :)

@sqla-tester
Copy link
Copy Markdown
Collaborator

mike bayer (zzzeek) wrote:

thanks for the review!

View this in Gerrit at https://gerrit.sqlalchemy.org/c/sqlalchemy/sqlalchemy/+/3352

sqlalchemy-bot pushed a commit that referenced this pull request Dec 6, 2021
Added support for ``copy()`` and ``deepcopy()`` to the :class:`_url.URL`
class. Pull request courtesy Tom Ritchford.

Fixes: #7400
Closes: #7401
Pull-request: #7401
Pull-request-sha: a2c1b89

Change-Id: I55977338b2655a7d4f733ae786d31e589185e9ca
(cherry picked from commit 924cc31)
@rec rec deleted the copy branch December 7, 2021 15:10
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.

3 participants