Skip to content

Improve #1092 #1084 by removing mutable method default arguments#1093

Merged
seratch merged 1 commit intoslackapi:mainfrom
seratch:pr-1092-improvement
Aug 13, 2021
Merged

Improve #1092 #1084 by removing mutable method default arguments#1093
seratch merged 1 commit intoslackapi:mainfrom
seratch:pr-1092-improvement

Conversation

@seratch
Copy link
Copy Markdown
Contributor

@seratch seratch commented Aug 13, 2021

Summary

This pull request corrects a classic Python coding error 🤦 in #1084 #1092 . Passing mutable objects as default value for method arguments is a bad practice. The default value can be cached and can be shared among multiple instances. This pull request eliminates it by setting None to the arguments if nothing is passed.

Category (place an x in each of the [ ])

  • slack_sdk.web.WebClient (sync/async) (Web API client)
  • slack_sdk.webhook.WebhookClient (sync/async) (Incoming Webhook, response_url sender)
  • slack_sdk.socket_mode (Socket Mode client)
  • slack_sdk.signature (Request Signature Verifier)
  • slack_sdk.oauth (OAuth Flow Utilities)
  • slack_sdk.models (UI component builders)
  • slack_sdk.scim (SCIM API client)
  • slack_sdk.audit_logs (Audit Logs API client)
  • slack_sdk.rtm_v2 (RTM client)
  • /docs-src (Documents, have you run ./docs.sh?)
  • /docs-src-v2 (Documents, have you run ./docs-v2.sh?)
  • /tutorial (PythOnBoardingBot tutorial)
  • tests/integration_tests (Automated tests for this library)

Requirements (place an x in each [ ])

  • I've read and understood the Contributing Guidelines and have done my best effort to follow them.
  • I've read and agree to the Code of Conduct.
  • I've run python3 -m venv .venv && source .venv/bin/activate && ./scripts/run_validation.sh after making the changes.

@seratch seratch added bug M-T: A confirmed bug report. Issues are confirmed when the reproduction steps are documented web-client Version: 3x scim-client audit-logs-client labels Aug 13, 2021
@seratch seratch added this to the 3.9.0 milestone Aug 13, 2021
@codecov
Copy link
Copy Markdown

codecov bot commented Aug 13, 2021

Codecov Report

Merging #1093 (99be36c) into main (2b30100) will decrease coverage by 0.14%.
The diff coverage is 88.88%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #1093      +/-   ##
==========================================
- Coverage   86.19%   86.05%   -0.15%     
==========================================
  Files         110      110              
  Lines        9932     9932              
==========================================
- Hits         8561     8547      -14     
- Misses       1371     1385      +14     
Impacted Files Coverage Δ
slack_sdk/http_retry/builtin_handlers.py 60.52% <0.00%> (-31.58%) ⬇️
slack_sdk/audit_logs/v1/async_client.py 89.16% <100.00%> (ø)
slack_sdk/audit_logs/v1/client.py 91.20% <100.00%> (ø)
slack_sdk/scim/v1/async_client.py 94.20% <100.00%> (ø)
slack_sdk/scim/v1/client.py 93.75% <100.00%> (ø)
slack_sdk/web/async_base_client.py 98.33% <100.00%> (ø)
slack_sdk/web/base_client.py 89.55% <100.00%> (ø)
slack_sdk/webhook/async_client.py 92.23% <100.00%> (ø)
slack_sdk/webhook/client.py 94.59% <100.00%> (ø)
... and 2 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 2b30100...99be36c. Read the comment docs.

error: Optional[Exception] = None,
) -> bool:
return response.status_code == 429
return response is not None and response.status_code == 429
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

While running tests, some tests detected a potential error pattern where the response can be None when error is thrown.

@seratch seratch merged commit c07dc7b into slackapi:main Aug 13, 2021
@seratch seratch deleted the pr-1092-improvement branch August 13, 2021 09:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

audit-logs-client bug M-T: A confirmed bug report. Issues are confirmed when the reproduction steps are documented scim-client Version: 3x web-client

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant