diff --git a/packages/python-packages/api-stub-generator/tests/class_parsing_test.py b/packages/python-packages/api-stub-generator/tests/class_parsing_test.py index b96fddcc38b3..a78caa2d5de7 100644 --- a/packages/python-packages/api-stub-generator/tests/class_parsing_test.py +++ b/packages/python-packages/api-stub-generator/tests/class_parsing_test.py @@ -10,6 +10,7 @@ AliasNewType, AliasUnion, ClassWithDecorators, + ClassWithIvarsAndCvars, FakeTypedDict, FakeObject, GenericStack, @@ -40,6 +41,15 @@ class TestClassParsing: pkg_namespace = "apistubgentest.models" + def test_class_with_ivars_and_cvars(self): + obj = ClassWithIvarsAndCvars + class_node = ClassNode(name=obj.__name__, namespace=obj.__name__, parent_node=None, obj=obj, pkg_root_namespace=self.pkg_namespace) + actuals = _render_lines(_tokenize(class_node)) + expected = [ + "class ClassWithIvarsAndCvars:", + ] + _check_all(actuals, expected, obj) + def test_class_with_decorators(self): obj = ClassWithDecorators class_node = ClassNode(name=obj.__name__, namespace=obj.__name__, parent_node=None, obj=obj, pkg_root_namespace=self.pkg_namespace) diff --git a/packages/python-packages/apistubgentest/apistubgentest/models/__init__.py b/packages/python-packages/apistubgentest/apistubgentest/models/__init__.py index 32df3cef3dc8..6fcf0f263b3d 100644 --- a/packages/python-packages/apistubgentest/apistubgentest/models/__init__.py +++ b/packages/python-packages/apistubgentest/apistubgentest/models/__init__.py @@ -11,6 +11,7 @@ AliasNewType, AliasUnion, ClassWithDecorators, + ClassWithIvarsAndCvars, DocstringClass, FakeError, FakeObject, @@ -41,6 +42,7 @@ "AliasNewType", "AliasUnion", "ClassWithDecorators", + "ClassWithIvarsAndCvars", "DataClassSimple", "DataClassWithFields", "DataClassDynamic", diff --git a/packages/python-packages/apistubgentest/apistubgentest/models/_models.py b/packages/python-packages/apistubgentest/apistubgentest/models/_models.py index 74ea0e5e99d5..414a844c1d33 100644 --- a/packages/python-packages/apistubgentest/apistubgentest/models/_models.py +++ b/packages/python-packages/apistubgentest/apistubgentest/models/_models.py @@ -11,7 +11,7 @@ from collections.abc import Sequence from enum import Enum, EnumMeta import functools -from typing import Any, overload, Dict, TypedDict, Union, Optional, Generic, TypeVar, NewType, TypeAlias +from typing import Any, overload, Dict, TypedDict, Union, Optional, Generic, TypeVar, NewType, ClassVar from ._mixin import MixinWithOverloads @@ -45,10 +45,18 @@ def __init__(self, id, *args, **kwargs): cls.__init__ = __init__ return cls + @add_id class ClassWithDecorators: pass + +class ClassWithIvarsAndCvars: + captain: str = "Picard" # instance var w/ default + damage: int # instance var w/out default + stats: ClassVar[Dict[str, int]] = {} # class var + + class PublicCaseInsensitiveEnumMeta(EnumMeta): def __getitem__(self, name: str): pass