Skip to content

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

Merged

Conversation

jeffwidman
Copy link
Contributor

@jeffwidman jeffwidman commented Sep 12, 2017

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

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)))
Copy link
Contributor Author

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)))
Copy link
Contributor Author

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)
Copy link
Contributor Author

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?

@tvoinarovskyi
Copy link
Collaborator

LGTM. I'd leave the arguments, as it's more explicit.

@tvoinarovskyi tvoinarovskyi merged commit b1ae45c into master Sep 13, 2017
@tvoinarovskyi tvoinarovskyi deleted the 1212-stop-using-mutable-types-for-default-arg-values branch September 13, 2017 19:03
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.

3 participants