Skip to content

Commit

Permalink
docs: added missing docstrings
Browse files Browse the repository at this point in the history
  • Loading branch information
doctrino committed Aug 18, 2024
1 parent cdbc88a commit 301c289
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions cognite/pygen/_core/models/data_classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -559,14 +559,17 @@ def container_field_variables(self) -> str:

@property
def filter_name(self) -> str:
"""The name of the filter class."""
return f"_create_{self.variable}_filter"

@property
def is_edge_class(self) -> bool:
"""Check if the data class is an edge class."""
return False

@property
def connections_docs_write(self) -> str:
"""Return a string with all connections that are write fields."""
connections = [f for f in self.fields_of_type(BaseConnectionField) if f.destination_class and f.is_write_field] # type: ignore[type-abstract]
if len(connections) == 0:
raise ValueError("No connections found")
Expand All @@ -577,6 +580,7 @@ def connections_docs_write(self) -> str:

@property
def connections_docs(self) -> str:
"""Return a string with all connections."""
connections = [f for f in self.fields_of_type(BaseConnectionField) if f.destination_class] # type: ignore[type-abstract]
if len(connections) == 0:
raise ValueError("No connections found")
Expand All @@ -587,17 +591,20 @@ def connections_docs(self) -> str:

@property
def import_pydantic_field(self) -> str:
"""Import the pydantic field used in the data class."""
if self.pydantic_field == "Field":
return "from pydantic import Field"
else:
return "import pydantic"

@property
def has_any_field_model_prefix(self) -> bool:
"""Check if any field has a model prefix."""
return any(field_.name.startswith("model") for field_ in self)

@property
def has_edges(self) -> bool:
"""Check if the data class has any edges."""
return any(isinstance(field_, BaseConnectionField) and field_.is_edge for field_ in self)

@property
Expand All @@ -616,6 +623,7 @@ class NodeDataClass(DataClass):

@property
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"
else:
Expand All @@ -631,17 +639,20 @@ class EdgeDataClass(DataClass):

@property
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"
else:
return f"{self.read_name}Properties"

@property
def is_edge_class(self) -> bool:
"""Check if the data class is an edge class."""
return True

@property
def end_node_field(self) -> EndNodeField:
"""The end node field of the edge class."""
if self._end_node_field:
return self._end_node_field
raise ValueError("EdgeDataClass has not been initialized.")
Expand All @@ -655,6 +666,7 @@ def update_fields(
has_default_instance_space: bool,
config: pygen_config.PygenConfig,
):
"""Update the fields of the data class."""
# Find all node views that have an edge with properties in this view
# and get the node class it is pointing to.
edge_classes: dict[tuple[str, dm.DirectRelationReference, str], EdgeClass] = {}
Expand Down

0 comments on commit 301c289

Please sign in to comment.