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

list_cards_iter doesn't work on second/multiple iterations #307

Open
MatthewSilverstein opened this issue Mar 13, 2020 · 1 comment
Open

Comments

@MatthewSilverstein
Copy link

MatthewSilverstein commented Mar 13, 2020

Hey,

The list_cards_iter doesn't work on second/multiple iterations because by default the query parameter is using the previous query value. The workaround is to just initialize the query parameter on each call. I'm just wondering if there's a reason for this or if it's a bug.

Here is some sample code where the list should be iterated twice:

for card in card_list.list_cards_iter(card_filter='all'):
    print(card.name)
for card in card_list.list_cards_iter(card_filter='all'):
    print(card.name)

Here is the workaround for actually iterating twice:

for card in card_list.list_cards_iter(card_filter='all', query={}):
    print(card.name)
for card in card_list.list_cards_iter(card_filter='all', query={}):
    print(card.name)

The fix is to change the query parameter to None instead of an empty dictionary: https://docs.quantifiedcode.com/python-anti-patterns/correctness/mutable_default_value_as_argument.html

Thanks,
Matt

@sarumont
Copy link
Owner

sarumont commented Mar 13, 2020 via email

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

No branches or pull requests

2 participants