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

Semantics generic parent #544

Open
wants to merge 11 commits into
base: mypy_semantics
Choose a base branch
from
Open

Conversation

liamhuber
Copy link
Member

@liamhuber liamhuber commented Jan 15, 2025

Some refactoring, namely getting rid of the HasParent interface (which was only used in a single place, Semantic, which can simply have that as part of its interface) and breaking SemanticParent out of the Semantic inheritance tree. These made it easier to then make Semantic generic on its parent type, so that type narrowing in Node(..., Semantic["Composite"], ...) gives us helpful type narrowing.

I think mypy --strict will still complain about the typevar definitions,

ParentType = TypeVar("ParentType", bound="SemanticParent")
ChildType = TypeVar("ChildType", bound="Semantic")

This is because the bounds are generic and we leave the resolution implicitly as typing.Any. At present I'm not concerned about this because (a) let's get mypy happy before worrying about mypy --strict, and (b) because of the circular way that Semantic(Generic[ParentType]) and SemanticParent(Generic[ChildType]), I think we are anyhow actually achieving

ParentType = TypeVar("ParentType", bound="SemanticParent[Semantic[SemanticParent[...]]")
ChildType = TypeVar("ChildType", bound="Semantic[SemanticParent[Semantic[...]]")

even though we obviously can't actually write that out.

TODO: Take a swing at delaying the specification of Semantic's generic type in Node, such that we don't need explicit handling of the parent-most behaviour of Workflow, but can do something like Workflow[Node[None]], while StaticNode[Node[Composite]] continues to behave in the current way. (It might be necessary to delay this until #360 is resolved and we can directly say Workflow[Semantic[None]] and Node[Semantic[Composite]] (or similar).

An interface class guaranteeing the (Any-typed) attribute is too vague to be super useful, and redundant when it's _only_ used in `Semantic`. Having a `parent` will just be a direct feature of being semantic.

Signed-off-by: liamhuber <[email protected]>
Signed-off-by: liamhuber <[email protected]>
Because of the label arg vs kwarg problem, there is still a vestigial label arg in the SemanticParent init signature.

Signed-off-by: liamhuber <[email protected]>
This is handled in the super class

Signed-off-by: liamhuber <[email protected]>
Signed-off-by: liamhuber <[email protected]>
Signed-off-by: liamhuber <[email protected]>
Signed-off-by: liamhuber <[email protected]>
Copy link

Binder 👈 Launch a binder notebook on branch pyiron/pyiron_workflow/semantics_generic_parent

Signed-off-by: liamhuber <[email protected]>
Copy link

codacy-production bot commented Jan 15, 2025

Coverage summary from Codacy

See diff coverage on Codacy

Coverage variation Diff coverage
-0.01% (target: -1.00%) 96.30%
Coverage variation details
Coverable lines Covered lines Coverage
Common ancestor commit (f0deac6) 3408 3118 91.49%
Head commit (72b87c4) 3406 (-2) 3116 (-2) 91.49% (-0.01%)

Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch: <coverage of head commit> - <coverage of common ancestor commit>

Diff coverage details
Coverable lines Covered lines Diff coverage
Pull request (#544) 27 26 96.30%

Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified: <covered lines added or modified>/<coverable lines added or modified> * 100%

See your quality gate settings    Change summary preferences

Codacy stopped sending the deprecated coverage status on June 5th, 2024. Learn more

@liamhuber liamhuber mentioned this pull request Jan 15, 2025
Signed-off-by: liamhuber <[email protected]>
@liamhuber liamhuber marked this pull request as draft January 15, 2025 01:03
@liamhuber
Copy link
Member Author

TODO: Take a swing at delaying the specification of Semantic's generic type in Node, such that we don't need explicit handling of the parent-most behaviour of Workflow, but can do something like Workflow[Node[None]], while StaticNode[Node[Composite]] continues to behave in the current way. (It might be necessary to delay this until #360 is resolved and we can directly say Workflow[Semantic[None]] and Node[Semantic[Composite]] (or similar).

None is anyhow outside the bounds of the typevar for semantic parents, so indeed let's postpone this change and hope it's even easier later.

@liamhuber liamhuber marked this pull request as ready for review January 15, 2025 21:52
@liamhuber liamhuber requested a review from XzzX January 15, 2025 21:59
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.

1 participant