-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Stop using mutable types for default arg values #1213
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
Stop using mutable types for default arg values #1213
Conversation
Using mutable types for default args is typically a no-no unless their surprising behavior is being explicitly abused, for an explanation see: http://effbot.org/zone/default-values.htm Fix #1212
@@ -22,7 +22,7 @@ | |||
|
|||
@pytest.fixture | |||
def client(mocker): | |||
return mocker.Mock(spec=KafkaClient(bootstrap_servers=[], api_version=(0, 9))) | |||
return mocker.Mock(spec=KafkaClient(bootstrap_servers=(), api_version=(0, 9))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this argument instead be omitted altogether?
@@ -19,7 +19,7 @@ | |||
|
|||
@pytest.fixture | |||
def client(mocker): | |||
_cli = mocker.Mock(spec=KafkaClient(bootstrap_servers=[], api_version=(0, 9))) | |||
_cli = mocker.Mock(spec=KafkaClient(bootstrap_servers=(), api_version=(0, 9))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this argument instead be omitted altogether?
@@ -398,7 +398,7 @@ def test_send_produce_request_raises_when_topic_unknown(self, protocol, conn): | |||
def test_correlation_rollover(self): | |||
with patch.object(SimpleClient, 'load_metadata_for_topics'): | |||
big_num = 2**31 - 3 | |||
client = SimpleClient(hosts=[], correlation_id=big_num) | |||
client = SimpleClient(hosts=(), correlation_id=big_num) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this argument instead be omitted altogether?
LGTM. I'd leave the arguments, as it's more explicit. |
Using mutable types for default args is typically a no-no unless their
surprising behavior is being explicitly abused, for an explanation see:
http://effbot.org/zone/default-values.htm
Note to reviewers: This is just a find-and-replace of
=[]
with=()
to see if the tests pass.Possibly some of these arguments aren't actually used and could simply be removed, for example
the test files. If you notice any of these, please comment and I will update the PR.
Fix #1212