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

Typed nodes and edges #1820

Merged
merged 27 commits into from
Jul 2, 2024
Merged

Typed nodes and edges #1820

merged 27 commits into from
Jul 2, 2024

Conversation

doctrino
Copy link
Contributor

Description

Please describe the change you have made.

Checklist:

  • Tests added/updated.
  • Documentation updated. Documentation is generated from docstrings - these must be updated according to your change.
    If a new method has been added it should be referenced in cognite.rst in order to generate docs based on its docstring.
  • Changelog updated in CHANGELOG.md.
  • Version bumped. If triggering a new release is desired, bump the version number in _version.py and pyproject.toml per semantic versioning.

@doctrino doctrino marked this pull request as ready for review June 19, 2024 07:09
@doctrino doctrino requested review from a team as code owners June 19, 2024 07:09
@doctrino doctrino requested review from arnels and removed request for a team June 19, 2024 07:09
Copy link
Collaborator

@erlendvollset erlendvollset left a comment

Choose a reason for hiding this comment

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

Very nice! I really like this!

cognite/client/_api/data_modeling/instances.py Outdated Show resolved Hide resolved
cognite/client/_api/data_modeling/instances.py Outdated Show resolved Hide resolved
@erlendvollset
Copy link
Collaborator

Would be great with an example in the docs aswell!

Copy link

codecov bot commented Jun 20, 2024

Codecov Report

Attention: Patch coverage is 90.93750% with 29 lines in your changes missing coverage. Please review.

Project coverage is 92.75%. Comparing base (0ab6dd0) to head (ffe90fc).

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1820      +/-   ##
==========================================
+ Coverage   92.68%   92.75%   +0.06%     
==========================================
  Files         121      122       +1     
  Lines       17950    18188     +238     
==========================================
+ Hits        16637    16870     +233     
- Misses       1313     1318       +5     
Files Coverage Δ
cognite/client/_version.py 100.00% <100.00%> (ø)
...nite/client/data_classes/data_modeling/__init__.py 100.00% <100.00%> (ø)
cognite/client/data_classes/data_modeling/core.py 78.78% <100.00%> (+10.55%) ⬆️
...te/client/data_classes/data_modeling/data_types.py 96.89% <100.00%> (+0.03%) ⬆️
...ite/client/data_classes/data_modeling/instances.py 92.93% <96.72%> (-0.09%) ⬇️
...ient/data_classes/data_modeling/typed_instances.py 91.92% <91.92%> (ø)
cognite/client/_api/data_modeling/instances.py 87.76% <84.78%> (+0.83%) ⬆️

... and 3 files with indirect coverage changes

@doctrino doctrino changed the title Writable typed nodes and edges Typed nodes and edges Jun 28, 2024
@@ -389,7 +401,16 @@ def __contains__(self, attr: str) -> bool:
self.__raise_if_non_singular_source(attr)

def dump(self, camel_case: bool = True) -> dict[str, Any]:
dumped = super().dump(camel_case)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We cannot call the default dump method, as the TypedNode/Edge, will have properties directly on the class, which the default method just serialize in place.

doctrino and others added 7 commits July 1, 2024 18:59
The contained type was being inferred as Any
They only make sense if doing retrieving raw Nodes and Edges
Generic parameters and defaults don't mix well (see python/mypy#3737) so we need to use overloads instead, or InstancesResult is always InstancesResult[Any, Any]. Overloads don't work on retrieve() due to defaults and ordering of params, so we create two new methods that can be safely typed.
Then we can at least stay consistent within the DM client
@@ -77,54 +70,6 @@ def __init__(
self.description = description


class DataModelingInstancesList(WriteableCogniteResourceList, Generic[T_WriteClass, T_WritableCogniteResource], ABC):
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Probably need to add an alias here.

@doctrino doctrino merged commit 2e0e665 into master Jul 2, 2024
14 checks passed
@doctrino doctrino deleted the writable-typed-node-edges branch July 2, 2024 13:33
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.

None yet

2 participants