Skip to content

Commit 5417b70

Browse files
committed
feat: Add is_init_method property
1 parent fa01ac0 commit 5417b70

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

src/griffe/_internal/models.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -852,6 +852,11 @@ def is_type_alias(self) -> bool:
852852
"""
853853
return self.kind is Kind.TYPE_ALIAS
854854

855+
@property
856+
def is_init_method(self) -> bool:
857+
"""Whether this function is an `__init__` method."""
858+
return False
859+
855860
@property
856861
def is_init_module(self) -> bool:
857862
"""Whether this object is an `__init__.py` module.
@@ -1822,6 +1827,14 @@ def imports_future_annotations(self) -> bool:
18221827
"""Whether this module import future annotations."""
18231828
return cast("Module", self.final_target).imports_future_annotations
18241829

1830+
@property
1831+
def is_init_method(self) -> bool:
1832+
"""Whether this method is an `__init__` method.
1833+
1834+
See also: [`is_method`][griffe.Alias.is_method].
1835+
"""
1836+
return cast("Function", self.final_target).is_init_method
1837+
18251838
@property
18261839
def is_init_module(self) -> bool:
18271840
"""Whether this module is an `__init__.py` module.
@@ -2432,6 +2445,11 @@ def resolve(self, name: str) -> str:
24322445
return resolved
24332446
return super().resolve(name)
24342447

2448+
@property
2449+
def is_init_method(self) -> bool:
2450+
"""Whether this function is an `__init__` method."""
2451+
return bool(self.parent and self.parent.is_class and self.name == "__init__")
2452+
24352453
def as_dict(self, **kwargs: Any) -> dict[str, Any]:
24362454
"""Return this function's data as a dictionary.
24372455

0 commit comments

Comments
 (0)