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

Usando parâmetros default pra evitar checagem de conteúdo. #8

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

EwertonBello
Copy link

  • Usando parâmetros default pra evitar checagem de conteúdo.
  • Retirado exc_traceback do __exit__, parametro não utilizado.

src/measures.py Outdated
@@ -43,22 +43,20 @@ def __init__(self, client, addresses):
self.socket.setblocking(0)
self.time = functools.partial(_TimeContext, self.socket, client, addresses)

def count(self, metric, counter=1, dimensions=None):
def count(self, metric, counter=1, dimensions={}):
Copy link
Member

Choose a reason for hiding this comment

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

@EwertonBello it is dangerous to set argument as a empty dict, we have a full explanation here: https://stackoverflow.com/questions/26320899/why-is-the-empty-dictionary-a-dangerous-default-value-in-python

Copy link
Author

@EwertonBello EwertonBello Oct 2, 2020

Choose a reason for hiding this comment

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

@wpjunior Neste caso específico, utiliza-se update dimensions.update(message), não é acumulativo.

def f(value, key, hash={}):
    hash.update({'k':key})
    return hash

output

print(f('a', 1))
{'k': 1}
print(f('b', 2))
{'k': 2}

No exemplo problemático exposto no artigo:

def f(value, key, hash={}):
    hash[value] = key
    return hash

output

print(f('a', 1))
{'a': 1}
print(f('b', 2))
{'a': 1, 'b': 2}

Porém, realmente um caso de atualização pode ocorrer. Então irei alterar o PR no que se refere aos dicts no parâmetro default.

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.

2 participants