While reviewing some code through codacy, Codacy gave an issue for the following piece of code:
def MyClass(OldClass):
def __init__(self, arg1, arg2, *args, **kwargs)
self.arg1 = arg1
self.arg2 = arg2
super(OldClass, self).__init__(*args, **kwargs)
With the following explanation:
Why is this an issue?
For example, calling super() with the base class as first argument is wrong:
class AnotherOldStyleClass(OldStyleClass): def __init__(self): super(OldStyleClass, self).__init__() The super invocation
should be:
super(AnotherOldStyleClass, self).__init__()
It seems to want me to do this:
def MyClass(OldClass):
def __init__(self, arg1, arg2, *args, **kwargs)
self.arg1 = arg1
self.arg2 = arg2
super(OldClass, self).__init__(*args, **kwargs)
Or perhaps this:
def MyClass(OldClass):
def __init__(self, arg1, arg2, *args, **kwargs)
super(MyClass, self).__init__(*args, **kwargs)
self.arg1 = arg1
self.arg2 = arg2
Can someone tell me which of these is correct and why this is the preferred behaviour?
For reference, here is as example that I found using option 2.
Edit: here is my code as it appears exactly. Which explains my error:
class TransferToBigQuery(GoogleCloudStorageToBigQueryOperator):
"""Class to transfer data from Google cloud storage to Big Query"""
def __init__(
self, id, bucket, destination_project_dataset_table, source_objects=None,
schema_fields=None, schema_object=None, source_format='CSV',
create_disposition='CREATE_IF_NEEDED',
skip_leading_rows=0, write_disposition='WRITE_EMPTY',
field_delimiter=',', max_id_key=None, file_xcom=None,
bigquery_conn_id='bigquery_default',
google_cloud_storage_conn_id='google_cloud_storage_default',
delegate_to=None, schema_update_options=(), *args, **kwargs):
super(GoogleCloudStorageToBigQueryOperator, self).__init__(*args,
**kwargs)
Why is this recommended?