[jira] [Commented] (AIRFLOW-2867) Airflow Python Code not compatible to coding guidelines and standards

2018-08-07 Thread ASF GitHub Bot (JIRA)


[ 
https://issues.apache.org/jira/browse/AIRFLOW-2867?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16572471#comment-16572471
 ] 

ASF GitHub Bot commented on AIRFLOW-2867:
-

feng-tao closed pull request #3714: [AIRFLOW-2867] Refactor code to conform 
Python standards & guidelines
URL: https://github.com/apache/incubator-airflow/pull/3714
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/airflow/contrib/hooks/bigquery_hook.py 
b/airflow/contrib/hooks/bigquery_hook.py
index aa8fc382a6..2a94580f50 100644
--- a/airflow/contrib/hooks/bigquery_hook.py
+++ b/airflow/contrib/hooks/bigquery_hook.py
@@ -206,7 +206,7 @@ def create_empty_table(self,
dataset_id,
table_id,
schema_fields=None,
-   time_partitioning={},
+   time_partitioning=None,
labels=None
):
 """
@@ -238,6 +238,8 @@ def create_empty_table(self,
 
 :return:
 """
+if time_partitioning is None:
+time_partitioning = dict()
 project_id = project_id if project_id is not None else self.project_id
 
 table_resource = {
@@ -286,7 +288,7 @@ def create_external_table(self,
   quote_character=None,
   allow_quoted_newlines=False,
   allow_jagged_rows=False,
-  src_fmt_configs={},
+  src_fmt_configs=None,
   labels=None
   ):
 """
@@ -352,6 +354,8 @@ def create_external_table(self,
 :type labels: dict
 """
 
+if src_fmt_configs is None:
+src_fmt_configs = {}
 project_id, dataset_id, external_table_id = \
 _split_tablename(table_input=external_project_dataset_table,
  default_project_id=self.project_id,
@@ -482,7 +486,7 @@ def run_query(self,
   labels=None,
   schema_update_options=(),
   priority='INTERACTIVE',
-  time_partitioning={}):
+  time_partitioning=None):
 """
 Executes a BigQuery SQL query. Optionally persists results in a 
BigQuery
 table. See here:
@@ -548,6 +552,8 @@ def run_query(self,
 """
 
 # TODO remove `bql` in Airflow 2.0 - Jira: [AIRFLOW-2513]
+if time_partitioning is None:
+time_partitioning = {}
 sql = bql if sql is None else sql
 
 if bql:
@@ -808,8 +814,8 @@ def run_load(self,
  allow_quoted_newlines=False,
  allow_jagged_rows=False,
  schema_update_options=(),
- src_fmt_configs={},
- time_partitioning={}):
+ src_fmt_configs=None,
+ time_partitioning=None):
 """
 Executes a BigQuery load command to load data from Google Cloud Storage
 to BigQuery. See here:
@@ -880,6 +886,10 @@ def run_load(self,
 # if it's not, we raise a ValueError
 # Refer to this link for more details:
 #   
https://cloud.google.com/bigquery/docs/reference/rest/v2/jobs#configuration.query.tableDefinitions.(key).sourceFormat
+if src_fmt_configs is None:
+src_fmt_configs = {}
+if time_partitioning is None:
+time_partitioning = {}
 source_format = source_format.upper()
 allowed_formats = [
 "CSV", "NEWLINE_DELIMITED_JSON", "AVRO", "GOOGLE_SHEETS",
@@ -1011,12 +1021,12 @@ def run_with_configuration(self, configuration):
 
 # Wait for query to finish.
 keep_polling_job = True
-while (keep_polling_job):
+while keep_polling_job:
 try:
 job = jobs.get(
 projectId=self.project_id,
 jobId=self.running_job_id).execute()
-if (job['status']['state'] == 'DONE'):
+if job['status']['state'] == 'DONE':
 keep_polling_job = False
 # Check if job had errors.
 if 'errorResult' in job['status']:
@@ -1045,7 +1055,7 @@ def poll_job_complete(self, job_id):
 jobs = self.service.jobs()
 try:
 job = jobs.get(projectId=self.project_id, jobId=job_id).execute()
-if (job['status']['state'] == 'DONE'):
+if job['status']['state'] == 'DONE':
 return True
 except HttpError as err:
 if err.resp.status in [500, 503]:
@@ 

[jira] [Commented] (AIRFLOW-2867) Airflow Python Code not compatible to coding guidelines and standards

2018-08-07 Thread ASF GitHub Bot (JIRA)


[ 
https://issues.apache.org/jira/browse/AIRFLOW-2867?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16572266#comment-16572266
 ] 

ASF GitHub Bot commented on AIRFLOW-2867:
-

kaxil opened a new pull request #3714: [AIRFLOW-2867] Refactor code to conform 
Python standards & guidelines
URL: https://github.com/apache/incubator-airflow/pull/3714
 
 
   
   Make sure you have checked _all_ steps below.
   
   ### Jira
   
   - [x] My PR addresses the following [Airflow 
Jira](https://issues.apache.org/jira/browse/AIRFLOW/) issues and references 
them in the PR title. For example, "\[AIRFLOW-XXX\] My Airflow PR"
 - https://issues.apache.org/jira/browse/AIRFLOW-2867
   
   ### Description
   
   - [x] Here are some details about my PR, including screenshots of any UI 
changes:
   - Dictionary creation should be written by dictionary literal
   - Python’s default arguments are evaluated once when the function is 
defined, not each time the function is called (like it is in say, Ruby). This 
means that if you use a mutable default argument and mutate it, you will and 
have mutated that object for all future calls to the function as well.
   - Functions calling sets which can be replaced by set literal are now 
replaced by set literal
   - Replace list literals
   - Some of the static methods haven't been set static
   - Remove redundant parentheses
   
   
   ### Tests
   
   - [x] My PR adds the following unit tests __OR__ does not need testing for 
this extremely good reason:
   N/a, Nothing new added
   
   ### Commits
   
   - [x] My commits all reference Jira issues in their subject lines, and I 
have squashed multiple commits if they address the same issue. In addition, my 
commits follow the guidelines from "[How to write a good git commit 
message](http://chris.beams.io/posts/git-commit/)":
 1. Subject is separated from body by a blank line
 1. Subject is limited to 50 characters (not including Jira issue reference)
 1. Subject does not end with a period
 1. Subject uses the imperative mood ("add", not "adding")
 1. Body wraps at 72 characters
 1. Body explains "what" and "why", not "how"
   
   ### Documentation
   
   - [x] In case of new functionality, my PR adds documentation that describes 
how to use it.
 - When adding new operators/hooks/sensors, the autoclass documentation 
generation needs to be added.
   
   ### Code Quality
   
   - [x] Passes `git diff upstream/master -u -- "*.py" | flake8 --diff`
   


This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


> Airflow Python Code not compatible to coding guidelines and standards 
> --
>
> Key: AIRFLOW-2867
> URL: https://issues.apache.org/jira/browse/AIRFLOW-2867
> Project: Apache Airflow
>  Issue Type: Improvement
>Reporter: Kaxil Naik
>Assignee: Kaxil Naik
>Priority: Minor
> Fix For: 2.0.0
>
>
> Some of the Airflow code doesn't conform to python coding guidelines and 
> standards.
> The improvement I have analyzed are below:
> - Dictionary creation should be written by dictionary literal
> - Mutable default argument. Python’s default arguments are evaluated once 
> when the function is defined, not each time the function is called (like it 
> is in say, Ruby). This means that if you use a mutable default argument and 
> mutate it, you will and have mutated that object for all future calls to the 
> function as well.
> - Functions calling sets can be replaced by set literal 
> - Replace list literals
> - Some of the static methods haven't been set static
> - Redundant parentheses



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)