Skip to content

Commit

Permalink
Fix #5197.
Browse files Browse the repository at this point in the history
  • Loading branch information
tjprescott committed Mar 7, 2023
1 parent 2439409 commit 915d61e
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
AliasNewType,
AliasUnion,
ClassWithDecorators,
ClassWithIvarsAndCvars,
FakeTypedDict,
FakeObject,
GenericStack,
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
AliasNewType,
AliasUnion,
ClassWithDecorators,
ClassWithIvarsAndCvars,
DocstringClass,
FakeError,
FakeObject,
Expand Down Expand Up @@ -41,6 +42,7 @@
"AliasNewType",
"AliasUnion",
"ClassWithDecorators",
"ClassWithIvarsAndCvars",
"DataClassSimple",
"DataClassWithFields",
"DataClassDynamic",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 915d61e

Please sign in to comment.