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

Refactoring/#221 fixed mypy warnings #225

Open
wants to merge 22 commits into
base: main
Choose a base branch
from

Conversation

ckunki
Copy link
Contributor

@ckunki ckunki commented Nov 22, 2024

Closes #221
Closes #222
Closes #223

in RegisterPeerForwarder
RegisterPeerForwarderBuilderParameter
RegisterPeerForwarderFactory
predecessor=message.source,
predecessor_send_socket_factory=predecessor_send_socket_factory,
successor=message.peer,
successor_send_socket_factory=successor_send_socket_factory,
my_connection_info=self._my_connection_info,
)

@property
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Property method register_peer_connection checks the private attribute _register_peer_connection and raises an exception when it is None to avoid code duplication.

Questions:

  • Q1) The names of the private attribute and the property differ on in the prefix _ and potentially could be mixed up. Should we use different names that can easier be distinguished?
  • Q2) The property is public. Should it be private?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

See last push

raise RuntimeError("No current query handler set.")
return value

@property
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Property method current_query_handler_context checks the private attribute _current_query_handler_context and raises an exception when it is None to avoid code duplication.

Questions:

  • Q1) The names of the private attribute and the property differ on in the prefix _ and potentially could be mixed up. Should we use different names that can easier be distinguished?
  • Q2) The property is public. Should it be private?

Copy link
Collaborator

@tkilias tkilias Nov 25, 2024

Choose a reason for hiding this comment

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

If the original is private, the new one needs to be private, too. This means it needs another name. Good question, what the name should be. The same is true for current_stage property. Thinking about a prefix like _checked_*.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍 I like the proposal _checked_*.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I now used

  • @property _checked_current_qh_context(self)
  • attribute self._current_qh_context

Copy link
Contributor Author

Choose a reason for hiding this comment

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

See last push

@@ -37,6 +39,8 @@ def with_table_like_name(
return self

def build(self) -> ColumnName:
if self._name is None:
raise TypeCheckError("Name must not be None.")
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is it OK to raise a TypeCheckError here (same as typeguard does)?
Raising a different Error such as ValueError would require to update the unit tests.

Copy link
Collaborator

Choose a reason for hiding this comment

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

it is not a typeguard typecheck, so I would create my own TypeCheckError. However, we can do this also in another PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

See #227

@@ -54,8 +55,15 @@ def _receive_from_localhost_leader(self) -> bytes:
self._check_sequence_number(specific_message_obj=specific_message_obj)
return frames[1].to_bytes()

@property
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Property method multi_node_communicator checks the private attribute _multi_node_communicator and raises an exception when it is None to avoid code duplication.

Questions:

  • Q1) The names of the private attribute and the property differ on in the prefix _ and potentially could be mixed up. Should we use different names that can easier be distinguished?
  • Q2) The property is public. Should it be private?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

See last push

@@ -94,18 +109,25 @@ def _send_local_leader_message_to_multi_node_leader(self):
local_position=local_position, value_frame=value_frame
)

@property
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Property method multi_node_communicator checks the private attribute _multi_node_communicator and raises an exception when it is None to avoid code duplication.

Questions:

  • Q1) The names of the private attribute and the property differ on in the prefix _ and potentially could be mixed up. Should we use different names that can easier be distinguished?
  • Q2) The property is public. Should it be private?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

See last push

@@ -1,6 +1,6 @@
import logging

import exasol.bucketfs as bfs
import exasol.bucketfs as bfs # type: ignore[import-untyped]
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think, we can do this in the pyproject.toml for all imports, but we probably should add py.typed to bucketfs-python

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, yes.
I created a ticket for adding file py.typed to bucketfs-python here: exasol/bucketfs-python#173

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks to @Nicoretti for helping: We can ignore importing untyped modules in pyproject.toml like this:

[[tool.mypy.overrides]]
module = "exasol.analytics.*"
disable_error_code = ["import-untyped"]

Additionally type check can be disabled in tests by

[[tool.mypy.overrides]]
module = [
    "tests.*",
    "noxfile",
]
ignore_errors = true

Copy link
Contributor Author

Choose a reason for hiding this comment

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

See last push

@@ -72,8 +73,8 @@ def _handle_continue(self, result: Continue) -> Union[Continue, Finish[ResultTyp
self._cleanup_query_handler_context()
self._execute_queries(result.query_list)
input_query_result = self._run_input_query(result)
result = self._state.query_handler.handle_query_result(input_query_result)
return result
_result = self._state.query_handler.handle_query_result(input_query_result)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why this rename?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because result was already a parameter of the method and mypy complained about potentially different types being assigned to the same variable.

return self._bucketfs_location

@property
def parameter(self) -> UDFParameter:
Copy link
Collaborator

Choose a reason for hiding this comment

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

these should be private, too

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK

Copy link
Contributor Author

Choose a reason for hiding this comment

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

See last push

self._parameter = None

@property
def bucketfs_location(self) -> bfs.path.PathLike:
Copy link
Collaborator

Choose a reason for hiding this comment

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

these should be private, too

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK

Copy link
Contributor Author

Choose a reason for hiding this comment

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

See last push

@@ -187,10 +211,10 @@ def release_and_create_query_handler_context_if_input_query(
current_state.top_level_query_handler_context.get_child_query_handler_context()
)

def _get_parameter(self, ctx):
def _get_parameter(self, ctx) -> UDFParameter:
iter_num = ctx[0]
Copy link
Collaborator

Choose a reason for hiding this comment

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

in another PR, we probably should replace the numbers with named constants

Copy link
Contributor Author

Choose a reason for hiding this comment

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

See #228

) -> UDFQueryResult:
colum_start_ix = 8 if self.parameter.iter_num == 0 else 4
if query_columns is None:
Copy link
Collaborator

Choose a reason for hiding this comment

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

questionable, needs more investigation

@@ -116,24 +117,28 @@ def _release_and_create_query_handler_context_of_input_query(self):
def _wrap_return_query(
self, input_query: SelectQueryWithColumnDefinition
) -> Tuple[str, str]:
if self._state.input_query_query_handler_context is None:
Copy link
Collaborator

Choose a reason for hiding this comment

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

needs investigation

Copy link
Contributor

@tomuben tomuben left a comment

Choose a reason for hiding this comment

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

Don't forget to activate the type checker in the CI !!! Otherwise all the work is in vain ;)

@ckunki
Copy link
Contributor Author

ckunki commented Nov 27, 2024

Don't forget to activate the type checker in the CI !!! Otherwise all the work is in vain ;)

I assume the type checker was activated all the time in checks.yml:

run: poetry run nox -s type-check

but mypy was told to ignore all package of the project in pyproject.toml. The latter I updated.

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.

Typo catched -> caught Make BackgroundListenerThread.poller private Fix mypy warnings
3 participants