Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Sbachmei/mic 5347/mypy resources #490

Merged
merged 2 commits into from
Oct 3, 2024

Conversation

stevebachmeier
Copy link
Contributor

fix mypy errors: framework/resource.py

Description

Changes and notes

Testing

producer: Callable,
dependencies: List[str],
resource_names: list[str],
producer: Callable[..., Any],
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'm not 100% clear on this, but I think a producer really can take anything as an arg and return anything? Would like to talk about it w/ someone who is more familiar w this resource stuff.

@@ -144,24 +149,24 @@ def sorted_nodes(self):
"""
if self._sorted_nodes is None:
try:
self._sorted_nodes = list(nx.algorithms.topological_sort(self.graph))
self._sorted_nodes = list(nx.algorithms.topological_sort(self.graph)) # type: ignore[func-returns-value]
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was giving an error that nx.algorithms.topological_sort alwasy returns None which simply isn't true. I didn't dig too deep but assume that the stub package I downloaded (which is not by the same folks who maintain networkx) simply typed it wrong.

Copy link
Contributor

Choose a reason for hiding this comment

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

Is it worth contributing a PR to the stubs package to fix this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Interesting, I'll take a look. I've never contributed to a 3rd party package before so that would be fun

@@ -44,6 +44,7 @@
"dill",
# Type stubs
"pandas-stubs",
"networkx-stubs",
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 this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

a stub package for networkx

@@ -250,7 +255,7 @@ def _to_graph(self) -> nx.DiGraph:
if dependency not in self._resource_group_map:
# Warn here because this sometimes happens naturally
# if observer components are missing from a simulation.
self.logger.warning(
self.logger.warning( # type: ignore[no-untyped-call]
Copy link
Contributor Author

Choose a reason for hiding this comment

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

untyped from loguru. I tried using the loguru-mypy package but it didn't get rid of this particular error wo I just ignore it

@@ -44,6 +44,7 @@
"dill",
# Type stubs
"pandas-stubs",
"networkx-stubs",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

a stub package for networkx

@@ -335,7 +340,7 @@ def add_resources(
"""
self._manager.add_resources(resource_type, resource_names, producer, dependencies)

def __iter__(self):
def __iter__(self) -> Iterator[Callable[..., Any]]:
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 think this is correct but I'd like to talk about this w/ someone familiar with python's implementation of iterables

@stevebachmeier stevebachmeier marked this pull request as draft October 3, 2024 17:56
@stevebachmeier stevebachmeier marked this pull request as ready for review October 3, 2024 18:07
# This will be a dict with string keys representing the the resource
# and the resource group they belong to. This is a one to many mapping
# as some resource groups contain many resources.
self._resource_group_map = {}
self._resource_group_map: dict[str, ResourceGroup] = {}
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you convert these inline comments to docstrings?

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 thought about doing that, but they won't show up b/c they're private anyway. Are you suggesting just so it's easier to know which comment goes w/ wihich attr?

@@ -144,24 +149,24 @@ def sorted_nodes(self):
"""
if self._sorted_nodes is None:
try:
self._sorted_nodes = list(nx.algorithms.topological_sort(self.graph))
self._sorted_nodes = list(nx.algorithms.topological_sort(self.graph)) # type: ignore[func-returns-value]
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it worth contributing a PR to the stubs package to fix this?

@stevebachmeier stevebachmeier force-pushed the sbachmei/mic-5347/mypy-resources branch from e624482 to 3818782 Compare October 3, 2024 22:16
@stevebachmeier stevebachmeier merged commit e6934bc into main Oct 3, 2024
6 checks passed
@stevebachmeier stevebachmeier deleted the sbachmei/mic-5347/mypy-resources branch October 3, 2024 22:20
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants