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: using f-string instead of string.format #428

Merged
merged 4 commits into from Dec 15, 2020
Merged

chore: using f-string instead of string.format #428

merged 4 commits into from Dec 15, 2020

Conversation

dungdm93
Copy link
Contributor

@dungdm93 dungdm93 commented Dec 14, 2020

Signed-off-by: Đặng Minh Dũng dungdm93@live.com

Summary of Changes

Currently, our repo is string.format heavy-using. Some of them are unnecessary like:

self._cluster = '{}'.format(conf.get_string(AthenaMetadataExtractor.CATALOG_KEY))

This PR is all about clean that up and make the code more concise by using f-string instead of string.format
Screenshot from 2020-12-14 14-19-21

Tests

No tests change. Already pass make test

Documentation

N/A

CheckList

Make sure you have checked all steps below to ensure a timely review.

  • PR title addresses the issue accurately and concisely. Example: "Updates the version of Flask to v1.0.2"
  • PR includes a summary of changes.
  • PR adds unit tests, updates existing unit tests, OR documents why no test additions or modifications are needed.
  • In case of new functionality, my PR adds documentation that describes how to use it.
    • All the public functions and the classes in the PR contain docstrings that explain what it does
  • PR passes make test

Signed-off-by: Đặng Minh Dũng <dungdm93@live.com>

self.sql_stmt = AthenaMetadataExtractor.SQL_STATEMENT.format(
where_clause_suffix=conf.get_string(AthenaMetadataExtractor.WHERE_CLAUSE_SUFFIX_KEY),
catalog_source=self._cluster
)

LOGGER.info('SQL for Athena metadata: {}'.format(self.sql_stmt))
LOGGER.info('SQL for Athena metadata: %s', self.sql_stmt)
Copy link
Contributor

Choose a reason for hiding this comment

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

I believe we should be using f here as well for consistency

Copy link
Contributor Author

@dungdm93 dungdm93 Dec 15, 2020

Choose a reason for hiding this comment

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

@allisonsuarez string.format or f-string is eager evaluation, which mean that the logging message still evaluate event it's not logged to output.
On other hand, LOGGER.info(format, args) is lazy evaluation. So in somehow, it's better.
What do you think?

@@ -71,7 +71,7 @@ def init(self, conf: ConfigTree) -> None:

self.sql_stmt = sql_alch_conf.get_string(SQLAlchemyExtractor.EXTRACT_SQL)

LOGGER.info('SQL for Db2 metadata: {}'.format(self.sql_stmt))
LOGGER.info('SQL for Db2 metadata: %s', self.sql_stmt)
Copy link
Contributor

Choose a reason for hiding this comment

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

same here, should use f as well

@@ -47,7 +47,7 @@ def _execute_query(self) -> Iterable[Any]:
Use cursor to execute the {sql}
:return:
"""
LOGGER.info('Executing query: \n{}'.format(self.sql))
LOGGER.info('Executing query: \n%s', self.sql)
Copy link
Contributor

Choose a reason for hiding this comment

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

same here

Copy link
Contributor

Choose a reason for hiding this comment

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

oh wait is this functionality you are leveraging from LOGGER.info?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep. It's API from LOGGER.info


from databuilder import Scoped
from databuilder.extractor.base_extractor import Extractor
from databuilder.extractor.sql_alchemy_extractor import SQLAlchemyExtractor
from databuilder.models.table_metadata import TableMetadata, ColumnMetadata
from itertools import groupby

from pyhocon import ConfigFactory, ConfigTree
Copy link
Member

Choose a reason for hiding this comment

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

typical python lib order based on https://www.python.org/dev/peps/pep-0008/

Imports should be grouped in the following order:

Standard library imports.
Related third party imports.
Local application/library specific imports.

Even we don't have CI to enforce it, it would good to still use this model (e.g databuilder import should come last) WDYT?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@feng-tao Do you mind if I setup a CI to check import order?

Copy link
Member

Choose a reason for hiding this comment

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

that will be great! thanks @dungdm93

Copy link
Contributor Author

Choose a reason for hiding this comment

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

isort_check added.
I also add .editorconfig file to make the code more consistent cross IDE.

@feng-tao could you please take a look.

@dungdm93 dungdm93 requested a review from a team as a code owner December 15, 2020 05:57
Signed-off-by: Đặng Minh Dũng <dungdm93@live.com>
Signed-off-by: Đặng Minh Dũng <dungdm93@live.com>
Copy link
Member

@feng-tao feng-tao left a comment

Choose a reason for hiding this comment

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

lgtm, will let @allisonsuarez take another look befor emerge, thanks @dungdm93 !

Signed-off-by: Đặng Minh Dũng <dungdm93@live.com>
@allisonsuarez
Copy link
Contributor

lgtm, will let @allisonsuarez take another look befor emerge, thanks @dungdm93 !

My only concern was with the logger.info changes, if that a part fo the function and doesn't require and f string I think this is good to go :) thanks @dungdm93 !

@feng-tao
Copy link
Member

@dungdm93 are you planning to add the github CI to check import order in a different pr?

@dungdm93
Copy link
Contributor Author

@feng-tao GitHub CI run make test and isort already added as a part of test script.
You could also check CI log to show it worked.

@feng-tao
Copy link
Member

@dungdm93 miss that part, lgtm then.

@feng-tao feng-tao merged commit cb8142e into amundsen-io:master Dec 15, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants