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

Added setdefault to BaseSettings #5821

Merged
merged 4 commits into from
Mar 7, 2023

Conversation

jxlil
Copy link
Contributor

@jxlil jxlil commented Feb 1, 2023

Added the setdefault method to the BaseSettings class.

Now setdefault works as expected, if the key does not exist in BaseSettings then this key will be added and default value will be assigned to it and this value will be returned. For example:

from scrapy.settings import BaseSettings

settings = BaseSettings()
# 'some_key' does not exist in BaseSettings, so it returns 'default_value'
print(settings.setdefault("some_key", "default_value"))

# 'some_key' now gets 'default_value'
print(settings.get("some_key"))

Closes #5811

@codecov
Copy link

codecov bot commented Feb 1, 2023

Codecov Report

Merging #5821 (33eda1c) into master (78eaf06) will increase coverage by 0.00%.
The diff coverage is 100.00%.

❗ Current head 33eda1c differs from pull request most recent head e8ee0d6. Consider uploading reports for the commit e8ee0d6 to get more accurate results

@@           Coverage Diff           @@
##           master    #5821   +/-   ##
=======================================
  Coverage   88.94%   88.95%           
=======================================
  Files         162      162           
  Lines       11002    11007    +5     
  Branches     1798     1799    +1     
=======================================
+ Hits         9786     9791    +5     
  Misses        937      937           
  Partials      279      279           
Impacted Files Coverage Δ
scrapy/settings/__init__.py 98.24% <100.00%> (+0.05%) ⬆️

@jxlil jxlil force-pushed the bugfix/basesettings-setdefault branch from 330af0e to a263ff0 Compare February 1, 2023 02:52
@jxlil jxlil changed the title Bugfix/basesettings setdefault Fix: BaseSettings.setdefault does nothing Feb 1, 2023
@jxlil jxlil changed the title Fix: BaseSettings.setdefault does nothing Fix: BaseSettings.setdefault does nothing Feb 1, 2023
@jxlil jxlil marked this pull request as ready for review February 6, 2023 16:33
@jxlil jxlil changed the title Fix: BaseSettings.setdefault does nothing Added setdefault to BaseSettings Feb 27, 2023
@Gallaecio
Copy link
Member

Nice!

@Gallaecio Gallaecio merged commit 8aca47e into scrapy:master Mar 7, 2023
@jxlil jxlil deleted the bugfix/basesettings-setdefault branch April 21, 2023 16:40
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.

BaseSettings.setdefault does nothing
3 participants