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

Implement Item.deepcopy() #3671

Merged
merged 1 commit into from
Mar 22, 2019
Merged

Implement Item.deepcopy() #3671

merged 1 commit into from
Mar 22, 2019

Conversation

Gallaecio
Copy link
Member

Fixes #1493

@codecov
Copy link

codecov bot commented Mar 8, 2019

Codecov Report

Merging #3671 into master will increase coverage by <.01%.
The diff coverage is 100%.

@@            Coverage Diff             @@
##           master    #3671      +/-   ##
==========================================
+ Coverage   84.72%   84.72%   +<.01%     
==========================================
  Files         168      168              
  Lines        9457     9461       +4     
  Branches     1407     1407              
==========================================
+ Hits         8012     8016       +4     
  Misses       1188     1188              
  Partials      257      257
Impacted Files Coverage Δ
scrapy/item.py 98.48% <100%> (+0.07%) ⬆️
scrapy/http/__init__.py 100% <0%> (ø) ⬆️

>>> print(product3)
Product(name='Desktop PC', price=1000, tags=['tag1'])

>>> product4 = product.deepcopy()
Copy link
Member

Choose a reason for hiding this comment

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

Hey, what do you think about providing some text describing it, not only an example? It'd be nice to mention caveats of using Product(product) or product.copy(), and tell where user should prefer which way of copying.

@Gallaecio Gallaecio force-pushed the item-deepcopy branch 2 times, most recently from fa03921 to b7d2a08 Compare March 22, 2019 15:09
@Gallaecio
Copy link
Member Author

I’ve created a separate documentation section just for copying items. There I introduce the concepts of shallow copy and deep copy with an example specific to Scrapy items, and link to the Python documentation for further information. Then I introduce the syntax variantes to copy Scrapy items with inline code examples.

scrapy/item.py Outdated
@@ -96,6 +97,13 @@ def __repr__(self):
def copy(self):
return self.__class__(self)

def deepcopy(self):
"""Returns a `deep copy`_ of this item.
Copy link
Member

Choose a reason for hiding this comment

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

Super-minor nitpick: according to PEP-257, it should be "Return ...", not "Returns ...".

The docstring is a phrase ending in a period. It prescribes the function or method's effect as a command ("Do this", "Return that"), not as a description; e.g. don't write "Returns the pathname ...".

@kmike
Copy link
Member

kmike commented Mar 22, 2019

Updated docs look awesome, thanks @Gallaecio!

@kmike kmike added this to the v1.7 milestone Mar 22, 2019
@kmike
Copy link
Member

kmike commented Mar 22, 2019

Thanks @Gallaecio! AppVeyor failure is not related to this PR, so I'm merging it.

@kmike kmike merged commit 729580d into scrapy:master Mar 22, 2019
@Gallaecio Gallaecio deleted the item-deepcopy branch March 22, 2019 18:54
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.

None yet

2 participants