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

node,scylla_node,cluster,scylla_cluster: Add type hints for nodes and clusters #609

Merged
merged 1 commit into from
Sep 26, 2024

Conversation

cezarmoise
Copy link
Contributor

  • Add type hints for nodes and clusters to help debugging in dtest
  • Fix linting / formatting issues

@cezarmoise cezarmoise self-assigned this Sep 12, 2024
@cezarmoise
Copy link
Contributor Author

I will do a jenkins run to check for issues

@fruch
Copy link
Contributor

fruch commented Sep 12, 2024

I would recommend add some linter that can identify those,
and configure it specific to check those files in CI.

I think ruff might be use to force adding type notation

or mypy --disallow-untyped-functions

@cezarmoise
Copy link
Contributor Author

I would recommend add some linter that can identify those, and configure it specific to check those files in CI.

I think ruff might be use to force adding type notation

or mypy --disallow-untyped-functions

Those tools check all function parameters. For example, with ruff I get that there are about 3000 untyped parameters or function returns.
I just added hints where nodes and clusters were involved, so it's easier for the editor to navigate trough their methods.

@cezarmoise
Copy link
Contributor Author

I will do a jenkins run to check for issues

https://jenkins.scylladb.com/view/master/job/scylla-master/job/byo/job/dtest-byo/564/
Ran without issues

@cezarmoise cezarmoise force-pushed the node-cluster-type-hints branch from 8d9a369 to df0a17a Compare September 25, 2024 08:43
@cezarmoise
Copy link
Contributor Author

df0a17a rebased to solve conflicts

Copy link

@pehala pehala left a comment

Choose a reason for hiding this comment

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

My only issue is that typing.* are deprecated since 3.9, because now you can use inbuilt types for typing instead, e.g. test: list[str] = []

See https://docs.python.org/3/library/typing.html#aliases-to-types-in-collections

Not sure whaat is our minimal working version, but 3.9 seems old & stable enough to do it the new way. @fruch WDYT?

@@ -1125,7 +1127,7 @@ def get_sstablespath(self, output_file=None, datafiles=None, keyspace=None, tabl
return sstablefiles

def run_sstablerepairedset(self, set_repaired=True, datafiles=None, keyspace=None, column_families=None):
cdir = self.get_install_dir()
cdir = self.get_install_dir() # noqa: F841
Copy link

@pehala pehala Sep 25, 2024

Choose a reason for hiding this comment

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

Why do we have unused-variables here? (Applies to all occurrences)

Copy link
Contributor

Choose a reason for hiding this comment

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

Cause we never linted this code.

This code path also probably isn't in use...

@fruch
Copy link
Contributor

fruch commented Sep 25, 2024

My only issue is that typing.* are deprecated since 3.9, because now you can use inbuilt types for typing instead, e.g. test: list[str] = []

See https://docs.python.org/3/library/typing.html#aliases-to-types-in-collections

Not sure whaat is our minimal working version, but 3.9 seems old & stable enough to do it the new way. @fruch WDYT?

The minimum is 3.8, we need to support the same versions as the python-driver does, cause ccm is used in it's testing

The typing.* isn't yet deprecated AFAIK, linters are suggesting not to use it.

Copy link
Contributor

@fruch fruch left a comment

Choose a reason for hiding this comment

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

LGTM

@@ -246,14 +249,14 @@ def add(self, node, is_seed, data_center=None, rack=None):

# nodes can be provided in multiple notations, determining the cluster topology:
# 1. int - specifying the number of nodes in a single DC, single RACK cluster
# 2. list[int] - specifying the number of nodes in a multi DC, single RACK per DC cluster
# 2. List[int] - specifying the number of nodes in a multi DC, single RACK per DC cluster
Copy link
Contributor

Choose a reason for hiding this comment

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

No real need to change those comments

def new_node(self, i, auto_bootstrap=False, debug=False, initial_token=None, add_node=True, is_seed=True, data_center=None, rack=None):
ipformat = self.get_ipformat()
def new_node(self, i, auto_bootstrap=False, debug=False, initial_token=None, add_node=True, is_seed=True, data_center=None, rack=None) -> ScyllaNode:
ipformat = self.get_ipformat() # noqa: F841
Copy link
Contributor

Choose a reason for hiding this comment

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

What is the point of introducing noqa ? If we don't introduce the linter as well ?

@@ -365,7 +368,7 @@ def get_storage_interface(self, nodeid):
return (self.get_node_ip(nodeid), 7000)

def get_node_jmx_port(self, nodeid):
return 7000 + nodeid * 100 + self.id;
Copy link
Contributor

Choose a reason for hiding this comment

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

Shame to get rid of ANSI C, isn't it ? 😜

@@ -421,7 +424,7 @@ def remove_dir_with_retry(self, path):
try:
common.rmdirs(path)
removed = True
except:
except Exception:
Copy link
Contributor

Choose a reason for hiding this comment

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

Linter should be angry about this, isn't it ? too broad exception ?

I think in this case we can set a specific set of possible exceptions

@fruch fruch merged commit b5f66dc into scylladb:next Sep 26, 2024
4 checks passed
@cezarmoise cezarmoise deleted the node-cluster-type-hints branch September 26, 2024 07:31
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