Skip to content

Sourcery refactored master branch#1

Open
sourcery-ai[bot] wants to merge 1 commit intomasterfrom
sourcery/master
Open

Sourcery refactored master branch#1
sourcery-ai[bot] wants to merge 1 commit intomasterfrom
sourcery/master

Conversation

@sourcery-ai
Copy link

@sourcery-ai sourcery-ai bot commented Feb 13, 2023

Branch master refactored by Sourcery.

If you're happy with these changes, merge this Pull Request using the Squash and merge strategy.

See our documentation here.

Run Sourcery locally

Reduce the feedback loop during development by using the Sourcery editor plugin:

Review changes via command line

To manually merge these changes, make sure you're on the master branch, then run:

git fetch origin sourcery/master
git merge --ff-only FETCH_HEAD
git reset HEAD^

Help us improve this pull request!

@sourcery-ai sourcery-ai bot requested a review from yelinaung February 13, 2023 15:24
Copy link
Author

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Sourcery timed out performing refactorings.

Due to GitHub API limits, only the first 60 comments can be shown.

if ';' in line:
requirement, _, specifier = line.partition(';')
for_specifier = EXTRAS.setdefault(':{}'.format(specifier), [])
for_specifier = EXTRAS.setdefault(f':{specifier}', [])
Copy link
Author

Choose a reason for hiding this comment

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

Lines 40-68 refactored with the following changes:

Comment on lines -84 to +96
htmlhelp_basename = '%sdoc' % project
htmlhelp_basename = f'{project}doc'

# Grouping the document tree into LaTeX files. List of tuples
# (source start file, target name, title, author, documentclass
# [howto/manual]).
latex_documents = [
('index',
'%s.tex' % project,
u'%s Documentation' % project,
u'Kubernetes', 'manual'),
(
'index',
f'{project}.tex',
f'{project} Documentation',
u'Kubernetes',
'manual',
)
Copy link
Author

Choose a reason for hiding this comment

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

Lines 84-93 refactored with the following changes:

resp = k8s_apps_v1.create_namespaced_deployment(
body=dep, namespace="default")
print("Deployment created. status='%s'" % resp.metadata.name)
print(f"Deployment created. status='{resp.metadata.name}'")
Copy link
Author

Choose a reason for hiding this comment

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

Function main refactored with the following changes:

Comment on lines -39 to +44
# Instantiate the deployment object
deployment = client.V1Deployment(
return client.V1Deployment(
api_version="apps/v1",
kind="Deployment",
metadata=client.V1ObjectMeta(name=DEPLOYMENT_NAME),
spec=spec)

return deployment
spec=spec,
)
Copy link
Author

Choose a reason for hiding this comment

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

Function create_deployment_object refactored with the following changes:

This removes the following comments ( why? ):

# Instantiate the deployment object

Comment on lines -54 to +52
print("Deployment created. status='%s'" % str(api_response.status))
print(f"Deployment created. status='{str(api_response.status)}'")
Copy link
Author

Choose a reason for hiding this comment

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

Function create_deployment refactored with the following changes:

# configuration.ssl_ca_cert="certificate"

aConfiguration.api_key = {"authorization": "Bearer " + aToken}
aConfiguration.api_key = {"authorization": f"Bearer {aToken}"}
Copy link
Author

Choose a reason for hiding this comment

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

Function main refactored with the following changes:

Comment on lines -271 to +276
sub_kls = re.match(r'list\[(.*)\]', klass).group(1)
sub_kls = re.match(r'list\[(.*)\]', klass)[1]
return [self.__deserialize(sub_data, sub_kls)
for sub_data in data]

if klass.startswith('dict('):
sub_kls = re.match(r'dict\(([^,]*), (.*)\)', klass).group(2)
sub_kls = re.match(r'dict\(([^,]*), (.*)\)', klass)[2]
Copy link
Author

Choose a reason for hiding this comment

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

Function ApiClient.__deserialize refactored with the following changes:

if post_params:
params = post_params

params = post_params or []
Copy link
Author

Choose a reason for hiding this comment

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

Function ApiClient.prepare_post_parameters refactored with the following changes:

Comment on lines -519 to +514
auth_setting = self.configuration.auth_settings().get(auth)
if auth_setting:
if auth_setting := self.configuration.auth_settings().get(auth):
Copy link
Author

Choose a reason for hiding this comment

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

Function ApiClient.update_params_for_auth refactored with the following changes:

Comment on lines -545 to +542
content_disposition = response.getheader("Content-Disposition")
if content_disposition:
filename = re.search(r'filename=[\'"]?([^\'"\s]+)[\'"]?',
content_disposition).group(1)
if content_disposition := response.getheader("Content-Disposition"):
filename = re.search(
r'filename=[\'"]?([^\'"\s]+)[\'"]?', content_disposition
)[1]
Copy link
Author

Choose a reason for hiding this comment

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

Function ApiClient.__deserialize_file refactored with the following changes:

Comment on lines -641 to +635
klass_name = instance.get_real_child_model(data)
if klass_name:
if klass_name := instance.get_real_child_model(data):
Copy link
Author

Choose a reason for hiding this comment

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

Function ApiClient.__deserialize_model refactored with the following changes:

Comment on lines -26 to +28
def __init__(cls, name, bases, dct):
super(TypeWithDefault, cls).__init__(name, bases, dct)
cls._default = None
def __init__(self, name, bases, dct):
super(TypeWithDefault, self).__init__(name, bases, dct)
self._default = None
Copy link
Author

Choose a reason for hiding this comment

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

Function TypeWithDefault.__init__ refactored with the following changes:

Comment on lines -30 to +33
def __call__(cls):
if cls._default is None:
cls._default = type.__call__(cls)
return copy.copy(cls._default)
def __call__(self):
if self._default is None:
self._default = type.__call__(self)
return copy.copy(self._default)
Copy link
Author

Choose a reason for hiding this comment

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

Function TypeWithDefault.__call__ refactored with the following changes:

Comment on lines -35 to +36
def set_default(cls, default):
cls._default = copy.copy(default)
def set_default(self, default):
self._default = copy.copy(default)
Copy link
Author

Choose a reason for hiding this comment

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

Function TypeWithDefault.set_default refactored with the following changes:

# Logging Settings
self.logger = {}
self.logger["package_logger"] = logging.getLogger("client")
self.logger = {"package_logger": logging.getLogger("client")}
Copy link
Author

Choose a reason for hiding this comment

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

Function Configuration.__init__ refactored with the following changes:

collection_formats=collection_formats)

def delete_collection_mutating_webhook_configuration(self, **kwargs): # noqa: E501
def delete_collection_mutating_webhook_configuration(self, **kwargs): # noqa: E501
Copy link
Author

Choose a reason for hiding this comment

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

Function AdmissionregistrationV1beta1Api.delete_collection_mutating_webhook_configuration refactored with the following changes:

Comment on lines -286 to +282
def delete_collection_mutating_webhook_configuration_with_http_info(self, **kwargs): # noqa: E501
def delete_collection_mutating_webhook_configuration_with_http_info(self, **kwargs): # noqa: E501
Copy link
Author

Choose a reason for hiding this comment

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

Function AdmissionregistrationV1beta1Api.delete_collection_mutating_webhook_configuration_with_http_info refactored with the following changes:

This removes the following comments ( why? ):

# noqa: E501
# HTTP header `Accept`

Comment on lines -395 to +405
def delete_collection_validating_webhook_configuration(self, **kwargs): # noqa: E501
def delete_collection_validating_webhook_configuration(self, **kwargs): # noqa: E501
Copy link
Author

Choose a reason for hiding this comment

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

Function AdmissionregistrationV1beta1Api.delete_collection_validating_webhook_configuration refactored with the following changes:

Comment on lines -430 to +436
def delete_collection_validating_webhook_configuration_with_http_info(self, **kwargs): # noqa: E501
def delete_collection_validating_webhook_configuration_with_http_info(self, **kwargs): # noqa: E501
Copy link
Author

Choose a reason for hiding this comment

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

Function AdmissionregistrationV1beta1Api.delete_collection_validating_webhook_configuration_with_http_info refactored with the following changes:

This removes the following comments ( why? ):

# noqa: E501
# HTTP header `Accept`

Comment on lines -539 to +559
def delete_mutating_webhook_configuration(self, name, **kwargs): # noqa: E501
def delete_mutating_webhook_configuration(self, name, **kwargs): # noqa: E501
Copy link
Author

Choose a reason for hiding this comment

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

Function AdmissionregistrationV1beta1Api.delete_mutating_webhook_configuration refactored with the following changes:

Comment on lines -567 to +583
def delete_mutating_webhook_configuration_with_http_info(self, name, **kwargs): # noqa: E501
def delete_mutating_webhook_configuration_with_http_info(self, name, **kwargs): # noqa: E501
Copy link
Author

Choose a reason for hiding this comment

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

Function AdmissionregistrationV1beta1Api.delete_mutating_webhook_configuration_with_http_info refactored with the following changes:

This removes the following comments ( why? ):

# noqa: E501
# HTTP header `Accept`

Comment on lines -659 to +679
def delete_validating_webhook_configuration(self, name, **kwargs): # noqa: E501
def delete_validating_webhook_configuration(self, name, **kwargs): # noqa: E501
Copy link
Author

Choose a reason for hiding this comment

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

Function AdmissionregistrationV1beta1Api.delete_validating_webhook_configuration refactored with the following changes:

Comment on lines -687 to +703
def delete_validating_webhook_configuration_with_http_info(self, name, **kwargs): # noqa: E501
def delete_validating_webhook_configuration_with_http_info(self, name, **kwargs): # noqa: E501
Copy link
Author

Choose a reason for hiding this comment

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

Function AdmissionregistrationV1beta1Api.delete_validating_webhook_configuration_with_http_info refactored with the following changes:

This removes the following comments ( why? ):

# noqa: E501
# HTTP header `Accept`

Comment on lines -779 to +799
def get_api_resources(self, **kwargs): # noqa: E501
def get_api_resources(self, **kwargs): # noqa: E501
Copy link
Author

Choose a reason for hiding this comment

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

Function AdmissionregistrationV1beta1Api.get_api_resources refactored with the following changes:

Comment on lines -800 to +816
def get_api_resources_with_http_info(self, **kwargs): # noqa: E501
def get_api_resources_with_http_info(self, **kwargs): # noqa: E501
Copy link
Author

Choose a reason for hiding this comment

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

Function AdmissionregistrationV1beta1Api.get_api_resources_with_http_info refactored with the following changes:

This removes the following comments ( why? ):

# noqa: E501
# HTTP header `Accept`

Comment on lines -315 to +321
def delete_custom_resource_definition_with_http_info(self, name, **kwargs): # noqa: E501
def delete_custom_resource_definition_with_http_info(self, name, **kwargs): # noqa: E501
Copy link
Author

Choose a reason for hiding this comment

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

Function ApiextensionsV1beta1Api.delete_custom_resource_definition_with_http_info refactored with the following changes:

This removes the following comments ( why? ):

# noqa: E501
# HTTP header `Accept`

Comment on lines -407 to +417
def get_api_resources(self, **kwargs): # noqa: E501
def get_api_resources(self, **kwargs): # noqa: E501
Copy link
Author

Choose a reason for hiding this comment

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

Function ApiextensionsV1beta1Api.get_api_resources refactored with the following changes:

Comment on lines -428 to +434
def get_api_resources_with_http_info(self, **kwargs): # noqa: E501
def get_api_resources_with_http_info(self, **kwargs): # noqa: E501
Copy link
Author

Choose a reason for hiding this comment

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

Function ApiextensionsV1beta1Api.get_api_resources_with_http_info refactored with the following changes:

This removes the following comments ( why? ):

# noqa: E501
# HTTP header `Accept`

Comment on lines -495 to +502
def list_custom_resource_definition(self, **kwargs): # noqa: E501
def list_custom_resource_definition(self, **kwargs): # noqa: E501
Copy link
Author

Choose a reason for hiding this comment

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

Function ApiextensionsV1beta1Api.list_custom_resource_definition refactored with the following changes:

Comment on lines -525 to +528
def list_custom_resource_definition_with_http_info(self, **kwargs): # noqa: E501
def list_custom_resource_definition_with_http_info(self, **kwargs): # noqa: E501
Copy link
Author

Choose a reason for hiding this comment

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

Function ApiextensionsV1beta1Api.list_custom_resource_definition_with_http_info refactored with the following changes:

This removes the following comments ( why? ):

# noqa: E501
# HTTP header `Accept`

@sourcery-ai
Copy link
Author

sourcery-ai bot commented Feb 13, 2023

Sourcery Code Quality Report

❌  Merging this PR will decrease code quality in the affected files by 0.04%.

Quality metrics Before After Change
Complexity 11.64 🙂 11.54 🙂 -0.10 👍
Method Length 141.91 😞 135.08 😞 -6.83 👍
Working memory 10.64 😞 10.68 😞 0.04 👎
Quality 45.79% 😞 45.75% 😞 -0.04% 👎
Other metrics Before After Change
Lines 35084 35242 158
Changed files Quality Before Quality After Quality Change
setup.py 51.20% 🙂 51.20% 🙂 0.00%
doc/source/conf.py 71.16% 🙂 70.86% 🙂 -0.30% 👎
examples/deployment_create.py 91.36% ⭐ 91.12% ⭐ -0.24% 👎
examples/deployment_crud.py 90.91% ⭐ 90.95% ⭐ 0.04% 👍
examples/job_crud.py 91.69% ⭐ 91.62% ⭐ -0.07% 👎
examples/pick_kube_config_context.py 79.18% ⭐ 79.07% ⭐ -0.11% 👎
examples/pod_config_list.py 79.18% ⭐ 79.07% ⭐ -0.11% 👎
examples/pod_exec.py 51.26% 🙂 51.70% 🙂 0.44% 👍
examples/pod_namespace_watch.py 70.88% 🙂 66.12% 🙂 -4.76% 👎
examples/remote_cluster.py 84.10% ⭐ 83.98% ⭐ -0.12% 👎
kubernetes/client/api_client.py 61.48% 🙂 61.20% 🙂 -0.28% 👎
kubernetes/client/configuration.py 82.81% ⭐ 83.05% ⭐ 0.24% 👍
kubernetes/client/rest.py 48.51% 😞 50.33% 🙂 1.82% 👍
kubernetes/client/api/admissionregistration_api.py 66.88% 🙂 69.20% 🙂 2.32% 👍
kubernetes/client/api/admissionregistration_v1beta1_api.py 46.61% 😞 46.60% 😞 -0.01% 👎
kubernetes/client/api/apiextensions_api.py 66.88% 🙂 69.20% 🙂 2.32% 👍
kubernetes/client/api/apiextensions_v1beta1_api.py 47.50% 😞 47.58% 😞 0.08% 👍
kubernetes/client/api/apiregistration_api.py 66.88% 🙂 69.20% 🙂 2.32% 👍
kubernetes/client/api/apiregistration_v1_api.py 47.50% 😞 47.58% 😞 0.08% 👍
kubernetes/client/api/apiregistration_v1beta1_api.py 47.50% 😞 47.58% 😞 0.08% 👍
kubernetes/client/api/apis_api.py 66.88% 🙂 69.20% 🙂 2.32% 👍
kubernetes/client/api/apps_api.py 66.88% 🙂 69.20% 🙂 2.32% 👍
kubernetes/client/api/apps_v1_api.py 42.77% 😞 42.80% 😞 0.03% 👍
kubernetes/client/api/apps_v1beta1_api.py 42.90% 😞 43.03% 😞 0.13% 👍
kubernetes/client/api/apps_v1beta2_api.py 42.77% 😞 42.83% 😞 0.06% 👍
kubernetes/client/api/auditregistration_api.py 66.88% 🙂 69.20% 🙂 2.32% 👍
kubernetes/client/api/auditregistration_v1alpha1_api.py 47.56% 😞 47.97% 😞 0.41% 👍
kubernetes/client/api/authentication_api.py 66.88% 🙂 69.20% 🙂 2.32% 👍
kubernetes/client/api/authentication_v1_api.py 57.68% 🙂 59.20% 🙂 1.52% 👍
kubernetes/client/api/authentication_v1beta1_api.py 57.68% 🙂 59.20% 🙂 1.52% 👍
kubernetes/client/api/authorization_api.py 66.88% 🙂 69.20% 🙂 2.32% 👍
kubernetes/client/api/authorization_v1_api.py 51.80% 🙂 52.84% 🙂 1.04% 👍
kubernetes/client/api/authorization_v1beta1_api.py 51.80% 🙂 52.84% 🙂 1.04% 👍
kubernetes/client/api/autoscaling_api.py 66.88% 🙂 69.20% 🙂 2.32% 👍
kubernetes/client/api/autoscaling_v1_api.py 43.86% 😞 43.82% 😞 -0.04% 👎
kubernetes/client/api/autoscaling_v2beta1_api.py 43.86% 😞 43.82% 😞 -0.04% 👎
kubernetes/client/api/autoscaling_v2beta2_api.py 43.86% 😞 43.89% 😞 0.03% 👍

Here are some functions in these files that still need a tune-up:

File Function Complexity Length Working Memory Quality Recommendation
kubernetes/client/rest.py RESTClientObject.request 35 ⛔ 418 ⛔ 17 ⛔ 14.80% ⛔ Refactor to reduce nesting. Try splitting into smaller methods. Extract out complex expressions
kubernetes/client/api_client.py ApiClient.__call_api 16 🙂 269 ⛔ 16 ⛔ 30.51% 😞 Try splitting into smaller methods. Extract out complex expressions
kubernetes/client/api/apps_v1_api.py AppsV1Api.delete_collection_namespaced_deployment_with_http_info 20 😞 402 ⛔ 11 😞 31.23% 😞 Refactor to reduce nesting. Try splitting into smaller methods. Extract out complex expressions
kubernetes/client/api/apps_v1_api.py AppsV1Api.delete_collection_namespaced_replica_set_with_http_info 20 😞 402 ⛔ 11 😞 31.23% 😞 Refactor to reduce nesting. Try splitting into smaller methods. Extract out complex expressions
kubernetes/client/api/apps_v1_api.py AppsV1Api.delete_collection_namespaced_stateful_set_with_http_info 20 😞 402 ⛔ 11 😞 31.23% 😞 Refactor to reduce nesting. Try splitting into smaller methods. Extract out complex expressions

Legend and Explanation

The emojis denote the absolute quality of the code:

  • ⭐ excellent
  • 🙂 good
  • 😞 poor
  • ⛔ very poor

The 👍 and 👎 indicate whether the quality has improved or gotten worse with this pull request.


Please see our documentation here for details on how these metrics are calculated.

We are actively working on this report - lots more documentation and extra metrics to come!

Help us improve this quality report!

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.

0 participants