diff options
Diffstat (limited to 'tests/roots/test-ext-autodoc')
4 files changed, 277 insertions, 5 deletions
diff --git a/tests/roots/test-ext-autodoc/target/enums.py b/tests/roots/test-ext-autodoc/target/enums.py index c69455f..6b27316 100644 --- a/tests/roots/test-ext-autodoc/target/enums.py +++ b/tests/roots/test-ext-autodoc/target/enums.py @@ -1,10 +1,46 @@ +# ruff: NoQA: D403, PIE796 import enum +from typing import final + + +class MemberType: + """Custom data type with a simple API.""" + + # this mangled attribute will never be shown on subclasses + # even if :inherited-members: and :private-members: are set + __slots__ = ('__data',) + + def __new__(cls, value): + self = object.__new__(cls) + self.__data = value + return self + + def __str__(self): + """inherited""" + return self.__data + + def __repr__(self): + return repr(self.__data) + + def __reduce__(self): + # data types must be pickable, otherwise enum classes using this data + # type will be forced to be non-pickable and have their __module__ set + # to '<unknown>' instead of, for instance, '__main__' + return self.__class__, (self.__data,) + + @final + @property + def dtype(self): + """docstring""" + return 'str' + + def isupper(self): + """inherited""" + return self.__data.isupper() class EnumCls(enum.Enum): - """ - this is enum class - """ + """this is enum class""" #: doc for val1 val1 = 12 @@ -15,9 +51,194 @@ class EnumCls(enum.Enum): def say_hello(self): """a method says hello to you.""" - pass @classmethod def say_goodbye(cls): """a classmethod says good-bye to you.""" - pass + + +class EnumClassWithDataType(MemberType, enum.Enum): + """this is enum class""" + + x = 'x' + + def say_hello(self): + """docstring""" + + @classmethod + def say_goodbye(cls): + """docstring""" + + +class ToUpperCase: # not inheriting from enum.Enum + @property + def value(self): # bypass enum.Enum.value + """uppercased""" + return str(self._value_).upper() # type: ignore[attr-defined] + + +class Greeter: + def say_hello(self): + """inherited""" + + @classmethod + def say_goodbye(cls): + """inherited""" + + +class EnumClassWithMixinType(ToUpperCase, enum.Enum): + """this is enum class""" + + x = 'x' + + def say_hello(self): + """docstring""" + + @classmethod + def say_goodbye(cls): + """docstring""" + + +class EnumClassWithMixinTypeInherit(Greeter, ToUpperCase, enum.Enum): + """this is enum class""" + + x = 'x' + + +class Overridden(enum.Enum): + def override(self): + """inherited""" + return 1 + + +class EnumClassWithMixinEnumType(Greeter, Overridden, enum.Enum): + """this is enum class""" + + x = 'x' + + def override(self): + """overridden""" + return 2 + + +class EnumClassWithMixinAndDataType(Greeter, ToUpperCase, MemberType, enum.Enum): + """this is enum class""" + + x = 'x' + + def say_hello(self): + """overridden""" + + @classmethod + def say_goodbye(cls): + """overridden""" + + def isupper(self): + """overridden""" + return False + + def __str__(self): + """overridden""" + return super().__str__() + + +class _ParentEnum(Greeter, Overridden, enum.Enum): + """docstring""" + + +class EnumClassWithParentEnum(ToUpperCase, MemberType, _ParentEnum, enum.Enum): + """this is enum class""" + + x = 'x' + + def isupper(self): + """overridden""" + return False + + def __str__(self): + """overridden""" + return super().__str__() + + +class _SunderMissingInNonEnumMixin: + @classmethod + def _missing_(cls, value): + """inherited""" + return super()._missing_(value) # type: ignore[misc] + + +class _SunderMissingInEnumMixin(enum.Enum): + @classmethod + def _missing_(cls, value): + """inherited""" + return super()._missing_(value) + + +class _SunderMissingInDataType(MemberType): + @classmethod + def _missing_(cls, value): + """inherited""" + return super()._missing_(value) # type: ignore[misc] + + +class EnumSunderMissingInNonEnumMixin(_SunderMissingInNonEnumMixin, enum.Enum): + """this is enum class""" + + +class EnumSunderMissingInEnumMixin(_SunderMissingInEnumMixin, enum.Enum): + """this is enum class""" + + +class EnumSunderMissingInDataType(_SunderMissingInDataType, enum.Enum): + """this is enum class""" + + +class EnumSunderMissingInClass(enum.Enum): + """this is enum class""" + + @classmethod + def _missing_(cls, value): + """docstring""" + return super()._missing_(value) + + +class _NamePropertyInNonEnumMixin: + @property + def name(self): + """inherited""" + return super().name # type: ignore[misc] + + +class _NamePropertyInEnumMixin(enum.Enum): + @property + def name(self): + """inherited""" + return super().name + + +class _NamePropertyInDataType(MemberType): + @property + def name(self): + """inherited""" + return super().name # type: ignore[misc] + + +class EnumNamePropertyInNonEnumMixin(_NamePropertyInNonEnumMixin, enum.Enum): + """this is enum class""" + + +class EnumNamePropertyInEnumMixin(_NamePropertyInEnumMixin, enum.Enum): + """this is enum class""" + + +class EnumNamePropertyInDataType(_NamePropertyInDataType, enum.Enum): + """this is enum class""" + + +class EnumNamePropertyInClass(enum.Enum): + """this is enum class""" + + @property + def name(self): + """docstring""" + return super().name diff --git a/tests/roots/test-ext-autodoc/target/functions.py b/tests/roots/test-ext-autodoc/target/functions.py index b62aa70..0265fb3 100644 --- a/tests/roots/test-ext-autodoc/target/functions.py +++ b/tests/roots/test-ext-autodoc/target/functions.py @@ -17,3 +17,6 @@ partial_coroutinefunc = partial(coroutinefunc) builtin_func = print partial_builtin_func = partial(print) + +def slice_arg_func(arg: 'float64[:, :]'): + pass diff --git a/tests/roots/test-ext-autodoc/target/inherited_annotations.py b/tests/roots/test-ext-autodoc/target/inherited_annotations.py new file mode 100644 index 0000000..3ae58a8 --- /dev/null +++ b/tests/roots/test-ext-autodoc/target/inherited_annotations.py @@ -0,0 +1,17 @@ +""" + Test case for #11387 corner case involving inherited + members with type annotations on python 3.9 and earlier +""" + +class HasTypeAnnotatedMember: + inherit_me: int + """Inherited""" + +class NoTypeAnnotation(HasTypeAnnotatedMember): + a = 1 + """Local""" + +class NoTypeAnnotation2(HasTypeAnnotatedMember): + a = 1 + """Local""" + diff --git a/tests/roots/test-ext-autodoc/target/singledispatchmethod_classmethod.py b/tests/roots/test-ext-autodoc/target/singledispatchmethod_classmethod.py new file mode 100644 index 0000000..039fada --- /dev/null +++ b/tests/roots/test-ext-autodoc/target/singledispatchmethod_classmethod.py @@ -0,0 +1,31 @@ +from functools import singledispatchmethod + + +class Foo: + """docstring""" + + @singledispatchmethod + @classmethod + def class_meth(cls, arg, kwarg=None): + """A class method for general use.""" + pass + + @class_meth.register(int) + @class_meth.register(float) + @classmethod + def _class_meth_int(cls, arg, kwarg=None): + """A class method for numbers.""" + pass + + @class_meth.register(str) + @classmethod + def _class_meth_str(cls, arg, kwarg=None): + """A class method for str.""" + pass + + @class_meth.register + @classmethod + def _class_meth_dict(cls, arg: dict, kwarg=None): + """A class method for dict.""" + # This function tests for specifying type through annotations + pass |