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

Move NodeType to its own file out of chia.server #19203

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

richardkiss
Copy link
Contributor

Purpose:

I've been trying out the tach tool, and it works really well. It's been helpful in finding files that are in the wrong place. This is another one.

This patch moves NodeType to chia.types which means chia.util no longer needs to depend upon chia.server (which seems pretty obviously bad).

Lots of other files import NodeType from chia.server.outbound_message (about 116). To keep this patch short, I've left the import in chia.server.outbound_message so I don't have to make 116 changes at this point, which would be a distraction in evaluating the idea here.

There are a couple other options: move the entire file chia/server/outbound_message.py to chia/types/outbound_message.py. We could also split out Message into its own file and/or move it to chia/types. What do you @arvidn @altendky think about these options?

Current Behavior:

New Behavior:

Testing Notes:

@richardkiss richardkiss added the Changed Required label for PR that categorizes merge commit message as "Changed" for changelog label Jan 28, 2025
@richardkiss richardkiss requested a review from a team as a code owner January 28, 2025 22:04
Copy link

Pull Request Test Coverage Report for Build 13020383560

Details

  • 13 of 13 (100.0%) changed or added relevant lines in 3 files are covered.
  • 11 unchanged lines in 5 files lost coverage.
  • Overall coverage increased (+0.04%) to 91.543%

Files with Coverage Reduction New Missed Lines %
chia/_tests/simulation/test_simulation.py 1 96.45%
chia/util/config.py 1 84.62%
chia/rpc/rpc_server.py 1 89.16%
chia/full_node/full_node.py 1 86.45%
chia/daemon/server.py 7 83.46%
Totals Coverage Status
Change from base Build 13019247618: 0.04%
Covered Lines: 105304
Relevant Lines: 114853

💛 - Coveralls

from typing import Optional, SupportsBytes, Union

from chia.protocols.protocol_message_types import ProtocolMessageTypes
from chia.types.node_type import NodeType # TODO: remove this and change a lot of `import` statements
Copy link
Contributor

Choose a reason for hiding this comment

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

i believe this will indicate an explicit re-export to mypy so we don't have to maintain a __all__.

Suggested change
from chia.types.node_type import NodeType # TODO: remove this and change a lot of `import` statements
from chia.types.node_type import NodeType as NodeType # TODO: remove this and change a lot of `import` statements

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unfortunately this change is giving me chia/server/outbound_message.py:7:34: PLC0414 Import alias does not rename original package

Copy link
Contributor

Choose a reason for hiding this comment

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

this is already a thing we intend to correct (per the TODO:) so i think an ignore is reasonable here.

Suggested change
from chia.types.node_type import NodeType # TODO: remove this and change a lot of `import` statements
# TODO: remove this and change a lot of `import` statements
from chia.types.node_type import NodeType as NodeType # noqa: PLC0414

i just really hate maintaining __all__, which won't generally happen i don't think unless some check catches it being out of date. and i despise even more when it is leveraged (* imports).

for example, i did:

https://github.com/Chia-Network/chia_rs/blob/f512dee8c880446faa96972bb78b9c65c250af13/wheel/python/chia_rs/datalayer.pyi#L96-L97

# just disallow * importing so we don't have to maintain this repetitive list
__all__: Sequence[str] = []

@richardkiss richardkiss marked this pull request as draft January 30, 2025 23:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Changed Required label for PR that categorizes merge commit message as "Changed" for changelog
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants