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

Code cleanup scrapy.utils.python.WeakKeyCache #4684 #4701

Merged
merged 7 commits into from Aug 5, 2020

Conversation

kshitijcode
Copy link
Contributor

@kshitijcode kshitijcode commented Jul 29, 2020

Resolves #4684

@kshitijcode
Copy link
Contributor Author

Cleaning up scrapy.utils.python.WeakKeyCache code and tests as per #4684

@wRAR
Copy link
Contributor

wRAR commented Jul 29, 2020

Flake8 failed, can you please fix that?

@kshitijcode
Copy link
Contributor Author

@wRAR : The failures don't seem to be related to my change

can you confirm, please?

@wRAR
Copy link
Contributor

wRAR commented Jul 29, 2020

Indeed.

@Gallaecio are these some known intermittent failures?

@kshitijcode
Copy link
Contributor Author

@wRAR : Can I try pushing in an empty commit ?

@codecov
Copy link

codecov bot commented Jul 30, 2020

Codecov Report

Merging #4701 into master will increase coverage by 0.03%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##           master    #4701      +/-   ##
==========================================
+ Coverage   86.29%   86.33%   +0.03%     
==========================================
  Files         160      160              
  Lines        9644     9672      +28     
  Branches     1415     1419       +4     
==========================================
+ Hits         8322     8350      +28     
  Misses       1062     1062              
  Partials      260      260              
Impacted Files Coverage Δ
scrapy/utils/python.py 85.71% <100.00%> (+0.25%) ⬆️
scrapy/utils/curl.py 100.00% <0.00%> (ø)
scrapy/pipelines/images.py 91.81% <0.00%> (ø)
scrapy/settings/default_settings.py 98.73% <0.00%> (+<0.01%) ⬆️
scrapy/utils/conf.py 93.13% <0.00%> (+0.06%) ⬆️
scrapy/extensions/feedexport.py 87.35% <0.00%> (+1.22%) ⬆️

@kshitijcode
Copy link
Contributor Author

@wRAR The indeed seem to be intermittent errors. Pushing an empty commit fixed it.

@wRAR
Copy link
Contributor

wRAR commented Jul 30, 2020

I've re-read the original issue, it talks about deprecating the class, not removing it, we don't remove non-deprecated classes/functions most of the time, can you please mark it as deprecated instead?

@kshitijcode
Copy link
Contributor Author

@wRAR : Would we like to bring back the test as well ?

@wRAR
Copy link
Contributor

wRAR commented Jul 30, 2020

No, I think it's fine to not test it as it's currently not used.

@kshitijcode
Copy link
Contributor Author

@wRAR @Gallaecio

Made the changes as requested 👍

@@ -273,6 +275,7 @@ def equal_attributes(obj1, obj2, attributes):
return True


@deprecated
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think it works on classes? Have you tried to instantiate it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@wRAR Yep, this is working with classes as inherently we are calling the __init__ function .

I tested it out and it gave me the following warning :

UserWarning: Call to deprecated function WeakKeyCache. Use The following API is deprecated Use instead.

Copy link
Member

Choose a reason for hiding this comment

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

Well, the message is inaccurate, “deprecated function WeakKeyCache”. We need to either make @deprecated smart enough to say ‘class’ when needed, or use a different approach. We’ve been using the latter so far, I’m not sure if there are potential unexpected side effects of using @deprecated after changing it to say “class” for classes.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@Gallaecio @wRAR What is the latter approach which has been used so far?

Also which is the existing test function?

Copy link
Member

Choose a reason for hiding this comment

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

@Gallaecio @wRAR What is the latter approach which has been used so far?

Logging a warning manually in the __init__ method, with ScrapyDeprecationWarning as warning class, and stacklevel=2 (so that the warning is about the call to __init__, and not about the implementation line where we log the warning).

Also which is the existing test function?

I did not get this, sorry. Could you elaborate?

@Gallaecio
Copy link
Member

No, I think it's fine to not test it as it's currently not used.

Actually, since the point of deprecating instead of removing is for things to remain working as expected for a while, I think it is better for the test to stay until we remove the class itself.

Also, it would be great to include a test that verifies that using the class logs the expected deprecation warning, or modify the existing test accordingly.

@kshitijcode
Copy link
Contributor Author

@Gallaecio @wRAR : Do we follow the principle of like deprecate in release and remove in subsequent release?

@Gallaecio
Copy link
Member

@Gallaecio @wRAR : Do we follow the principle of like deprecate in release and remove in subsequent release?

Nope. We only recently discussed internally our deprecation policy, and we are adding it to the documentation soon: deprecated code continues working for at least 1 year.

@kshitijcode
Copy link
Contributor Author

kshitijcode commented Aug 5, 2020

@wRAR @Gallaecio I went ahead with latter change as there doesn't seem to be reliable way to differentiate between a class/method.

Kindly review.

scrapy/utils/python.py Outdated Show resolved Hide resolved
scrapy/utils/python.py Outdated Show resolved Hide resolved
scrapy/utils/python.py Outdated Show resolved Hide resolved
@wRAR
Copy link
Contributor

wRAR commented Aug 5, 2020

Thank you!

@wRAR wRAR merged commit 1f0722c into scrapy:master Aug 5, 2020
2 checks passed
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.

Should scrapy.utils.python.WeakKeyCache be deprecated?
3 participants