Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
# Changelog
## Pedantic 2.3.1
- improve robustness of `WithDecoratedMethods`

## Pedantic 2.3.0
- added support for Python 3.14
- updated dependencies
Expand Down
5 changes: 4 additions & 1 deletion pedantic/mixins/with_decorated_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,10 @@ def get_decorated_functions(self) -> dict[DecoratorTypeVar, dict[C, T]]:
if attribute_name.startswith('__') or attribute_name in ['type_var', 'type_vars']:
continue

attribute = getattr(self, attribute_name)
try:
attribute = getattr(self, attribute_name)
except BaseException:
continue # ignore bad attributes

for decorator_type in decorator_types: # type: ignore
if hasattr(attribute, decorator_type):
Expand Down
18 changes: 17 additions & 1 deletion pedantic/tests/test_with_decorated_methods.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import unittest
from functools import wraps
from typing import TypeVar, Generic
from typing import TypeVar, Generic, NoReturn

from pedantic import DecoratorType, create_decorator, WithDecoratedMethods

Expand All @@ -16,6 +16,22 @@ class Decorators(DecoratorType):


class TestWithDecoratedMethods(unittest.TestCase):
def test_no_decorated_methods(self):
class MyClass(WithDecoratedMethods[Decorators]):
pass

instance = MyClass()
assert instance.get_decorated_functions() == {Decorators.FOO: {}, Decorators.BAR: {}}

def test_class_with_bad_property(self):
class MyClass(WithDecoratedMethods[Decorators]):
@property
def bad(self) -> NoReturn:
raise RuntimeError('bad man')

instance = MyClass()
assert instance.get_decorated_functions() == {Decorators.FOO: {}, Decorators.BAR: {}}

def test_with_decorated_methods_sync(self):
class MyClass(WithDecoratedMethods[Decorators]):
@foo(42)
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "pedantic"
version = "2.3.0"
version = "2.3.1"
description = "Some useful Python decorators for cleaner software development."
readme = "README.md"
requires-python = ">=3.11"
Expand Down