Skip to content

Commit

Permalink
🦍Adjustment of typed. (#292)
Browse files Browse the repository at this point in the history
* tests: updated test

* refactor: make typed private

* refactor: remove ruff complains
  • Loading branch information
doctrino authored Aug 21, 2024
1 parent e8e4fab commit 120f58a
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
8 changes: 4 additions & 4 deletions cognite/pygen/_core/models/data_classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -625,9 +625,9 @@ class NodeDataClass(DataClass):
def typed_properties_name(self) -> str:
"""The name of the typed properties class."""
if self.has_edge_class:
return f"{self.read_name.removesuffix('Node')}Properties"
return f"_{self.read_name.removesuffix('Node')}Properties"
else:
return f"{self.read_name}Properties"
return f"_{self.read_name}Properties"


@dataclass
Expand All @@ -641,9 +641,9 @@ class EdgeDataClass(DataClass):
def typed_properties_name(self) -> str:
"""The name of the typed properties class."""
if self.has_node_class:
return f"{self.read_name.removesuffix('Edge')}Properties"
return f"_{self.read_name.removesuffix('Edge')}Properties"
else:
return f"{self.read_name}Properties"
return f"_{self.read_name}Properties"

@property
def is_edge_class(self) -> bool:
Expand Down
8 changes: 7 additions & 1 deletion cognite/pygen/_core/models/fields/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,17 @@ def from_property(

doc_name = to_words(name, singularize=True)
variable = create_name(prop_name, field_naming.variable)
description: str | None = None
if hasattr(prop, "description") and isinstance(prop.description, str):
# This is a workaround for the fact that the description can contain curly quotes
# which is ruff will complain about. (These comes from che Core model)
description = prop.description.replace("‘", "'").replace("’", "'") # noqa: RUF001

base = cls(
name=name,
doc_name=doc_name,
prop_name=prop_name,
description=prop.description if hasattr(prop, "description") else None,
description=description,
pydantic_field=pydantic_field,
)
if isinstance(prop, dm.ConnectionDefinition) or (
Expand Down
2 changes: 1 addition & 1 deletion tests/test_integration/test_typed_classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def test_create_retrieve_delete(

@staticmethod
def create_core_multi_api_generator(client: CogniteClient) -> MultiAPIGenerator:
data_model = _get_data_model(("cdf_cdm_experimental", "core_data_model", "v1"), client, print)
data_model = _get_data_model(("cdf_cdm_experimental", "CogniteCore", "v1"), client, print)
# Ensure we have a random order of views
# This should be sorted before generating the typed classes
random.shuffle(data_model.views)
Expand Down

0 comments on commit 120f58a

Please sign in to comment.