Skip to content

Commit 5c75543

Browse files
committedMar 11, 2025·
Revert accedental commit
This reverts commit 5944e5f.
1 parent 807e532 commit 5c75543

File tree

2 files changed

+6
-32
lines changed

2 files changed

+6
-32
lines changed
 

‎src/codegen/sdk/core/class_definition.py

+5-27
Original file line numberDiff line numberDiff line change
@@ -110,29 +110,19 @@ def parent_class_names(self) -> list[Name | ChainedAttribute]:
110110
return []
111111

112112
@reader
113-
def get_parent_class(self, parent_class_name: str, optional: bool = False) -> Editable | None:
113+
def get_parent_class(self, parent_class_name: str) -> Editable | None:
114114
"""Returns the parent class node with the specified name.
115115
116116
Retrieves a parent class Name or ChainedAttribute node from this class's list of parent class names that matches
117117
the specified name.
118118
119119
Args:
120120
parent_class_name (str): The name of the parent class to find.
121-
optional (bool, optional): Whether to return None if the parent class is not found. Defaults to False.
122121
123122
Returns:
124123
Editable | None: The matching parent class node, or None if no match is found.
125124
"""
126-
parent_class = [p for p in self.parent_class_names if p.source == parent_class_name]
127-
if not parent_class:
128-
if not optional:
129-
msg = f"Parent class {parent_class_name} not found in class {self.name}. Use optional=True to return None instead."
130-
raise ValueError(msg)
131-
return None
132-
if len(parent_class) > 1:
133-
msg = f"Multiple parent classes found with name {parent_class_name} in class {self.name}."
134-
raise ValueError(msg)
135-
return parent_class[0]
125+
return next((p for p in self.parent_class_names if p.source == parent_class_name), None)
136126

137127
@property
138128
@reader
@@ -243,35 +233,30 @@ def methods(self, *, max_depth: int | None = 0, private: bool = True, magic: boo
243233
return list(result.values())
244234

245235
@reader
246-
def get_nested_class(self, name: str, optional: bool = False) -> Self | None:
236+
def get_nested_class(self, name: str) -> Self | None:
247237
"""Returns a nested class by name from the current class.
248238
249239
Searches through the nested classes defined in the class and returns the first one that matches the given name.
250240
251241
Args:
252242
name (str): The name of the nested class to find.
253-
optional (bool, optional): Whether to return None if the nested class is not found. Defaults to False.
254243
255244
Returns:
256245
Self | None: The nested class if found, None otherwise.
257246
"""
258247
for m in self.nested_classes:
259248
if m.name == name:
260249
return m
261-
if not optional:
262-
msg = f"Nested class {name} not found in class {self.name}. Use optional=True to return None instead."
263-
raise ValueError(msg)
264250
return None
265251

266252
@reader
267-
def get_method(self, name: str, optional: bool = False) -> TFunction | None:
253+
def get_method(self, name: str) -> TFunction | None:
268254
"""Returns a specific method by name from the class or any of its superclasses.
269255
270256
Searches through the class's methods and its superclasses' methods to find a method with the specified name.
271257
272258
Args:
273259
name (str): The name of the method to find.
274-
optional (bool, optional): Whether to return None if the method is not found. Defaults to False.
275260
276261
Returns:
277262
TFunction | None: The method if found, None otherwise.
@@ -282,9 +267,6 @@ def get_method(self, name: str, optional: bool = False) -> TFunction | None:
282267
for m in c.methods:
283268
if m.name == name:
284269
return m
285-
if not optional:
286-
msg = f"Method {name} not found in class {self.name}. Use optional=True to return None instead."
287-
raise ValueError(msg)
288270
return None
289271

290272
@proxy_property
@@ -311,14 +293,13 @@ def attributes(self, *, max_depth: int | None = 0, private: bool = True) -> list
311293
return list(result.values())
312294

313295
@reader
314-
def get_attribute(self, name: str, optional: bool = False) -> Attribute | None:
296+
def get_attribute(self, name: str) -> Attribute | None:
315297
"""Returns a specific attribute by name.
316298
317299
Searches for an attribute with the given name in the current class and its superclasses.
318300
319301
Args:
320302
name (str): The name of the attribute to search for.
321-
optional (bool, optional): Whether to return None if the attribute is not found. Defaults to False.
322303
323304
Returns:
324305
Attribute | None: The matching attribute if found, None otherwise. If multiple attributes with the same name exist in the inheritance hierarchy, returns the first one found.
@@ -329,9 +310,6 @@ def get_attribute(self, name: str, optional: bool = False) -> Attribute | None:
329310
for m in c.code_block.get_attributes(name):
330311
if m.name == name:
331312
return m
332-
if not optional:
333-
msg = f"Attribute {name} not found in class {self.name}. Use optional=True to return None instead."
334-
raise ValueError(msg)
335313
return None
336314

337315
####################################################################################################################

‎src/codegen/sdk/typescript/interfaces/has_block.py

+1-5
Original file line numberDiff line numberDiff line change
@@ -87,25 +87,21 @@ def jsx_elements(self) -> list[JSXElement[Self]]:
8787
return jsx_elements
8888

8989
@reader
90-
def get_component(self, component_name: str, optional: bool = False) -> JSXElement[Self] | None:
90+
def get_component(self, component_name: str) -> JSXElement[Self] | None:
9191
"""Returns a specific JSX element from within this symbol's JSX elements.
9292
9393
Searches through all JSX elements in this symbol's code block and returns the first one that matches
9494
the given component name.
9595
9696
Args:
9797
component_name (str): The name of the JSX component to find.
98-
optional (bool, optional): If True, return None if the component is not found. Defaults to False.
9998
10099
Returns:
101100
JSXElement[Self] | None: The matching JSX element if found, None otherwise.
102101
"""
103102
for component in self.jsx_elements:
104103
if component.name == component_name:
105104
return component
106-
if not optional:
107-
msg = f"Component {component_name} not found in symbol {self.name} of file {self.file_path}. Use optional=True to return None instead."
108-
raise ValueError(msg)
109105
return None
110106

111107
@cached_property

0 commit comments

Comments
 (0)
Please sign in to comment.