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

chore: Make methods that do not need to be instance methods static #2525

Merged
merged 3 commits into from
Jan 18, 2021

Conversation

aahung
Copy link
Contributor

@aahung aahung commented Jan 8, 2021

…static

Which issue(s) does this change fix?

Why is this change necessary?

There are many instance methods do not need to be instance methods since self is not being used. Making it static increases readability.

How does it address the issue?

Making them static. One exception, for BuildStrategy, the class is meant to be an abstract class, so I made its two instance methods abstract instead of static.

What side effects does this change have?

no,

A static method can be called either on the class (such as C.f()) or on an instance (such as C().f()). https://docs.python.org/3/library/functions.html#staticmethod

We don't need to change how we invoke them.

Checklist

  • Add input/output type hints to new functions/methods
  • Write design document (Do I need to write a design document?)
  • Write unit tests
  • Write/update functional tests
  • Write/update integration tests
  • make pr passes
  • make update-reproducible-reqs if dependencies were changed
  • Write documentation

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@aahung aahung changed the title chore: Make instance methods that do not need to be instance methods … chore: Make methods that do not need to be instance methods static Jan 8, 2021
Comment on lines -44 to +52
build_strategy = BuildStrategy(self.build_graph)
build_strategy = _TestBuildStrategy(self.build_graph)
Copy link
Contributor

Choose a reason for hiding this comment

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

would you explain why we need this "_TestBuildStrategy" class?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

BuildStrategy is an abstract class so I need to create a subclass to instantiate an object.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

(and adding prefix _ to indicate it is a "private" class)

@aahung aahung force-pushed the add-static-decorators branch from b97d294 to 1c59bf1 Compare January 18, 2021 21:17
@aahung
Copy link
Contributor Author

aahung commented Jan 18, 2021

(manually rebase the latest develop to resolve the conflict)

@aahung
Copy link
Contributor Author

aahung commented Jan 18, 2021

Added type hints except for ones requiring a lot effort

@aahung aahung merged commit d479678 into aws:develop Jan 18, 2021
@aahung aahung deleted the add-static-decorators branch January 18, 2021 23:31
mndeveci pushed a commit to mndeveci/aws-sam-cli that referenced this pull request Jan 19, 2021
…ws#2525)

* chore: Make instance methods that do not need to be instance methods static

* Add type hints to methods touched

* Merge develop
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