Skip to content

Commit 4a263bf

Browse files
committed
Fix
1 parent 45aad3b commit 4a263bf

File tree

4 files changed

+14
-7
lines changed

4 files changed

+14
-7
lines changed

docs/source/changelog.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ Glossary
2424
Releases
2525
---------------------
2626

27+
v1.2.1
28+
================
29+
- Replaced raw usage of ``.__annotations__`` with :func:`typing.get_typehints`.
30+
31+
2732
v1.2.0
2833
================
2934
- Added the ability of nicknaming structured objects.

docs/source/scripts/generate_autodoc.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
from enum import EnumMeta
2+
from typing import get_type_hints
3+
from pathlib import Path
24
import inspect
35
import os
46
import re
5-
from pathlib import Path
7+
68

79
OUTPUT_PATH = "../reference"
810

@@ -95,7 +97,7 @@
9597
if inspect.isfunction(item):
9698
if manual:
9799
_async_ = ":async:" if inspect.iscoroutinefunction(item) else ""
98-
annotations = item.__annotations__
100+
annotations = get_type_hints(item)
99101
return_ano = annotations.pop("return")
100102
doc_str = inspect.cleandoc(item.__doc__)
101103
# Replace titles with list titles

tkclasswiz/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
Works with Tkinter / TTKBootstrap.
44
"""
55

6-
__version__ = "1.2.0"
6+
__version__ = "1.2.1"
77

88
from .object_frame import *
99
from .annotations import *

tkclasswiz/annotations.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
Module used for managing annotations.
33
"""
44
from datetime import datetime, timedelta, timezone
5-
from typing import Union, Optional, get_args, Generic, get_origin
5+
from typing import Union, Optional, get_args, Generic, get_origin, get_type_hints
66
from contextlib import suppress
77
from inspect import isclass
88
from .doc import doc_category
@@ -96,17 +96,17 @@ def get_annotations(class_) -> dict:
9696
annotations = {}
9797
with suppress(AttributeError):
9898
if isclass(class_):
99-
annotations = class_.__init__.__annotations__.copy()
99+
annotations = get_type_hints(class_.__init__)
100100
elif isclass(origin_class := get_origin(class_)) and issubclass(origin_class, Generic):
101101
# Resolve generics
102-
annotations = origin_class.__init__.__annotations__.copy()
102+
annotations = get_type_hints(origin_class.__init__)
103103
generic_types = get_args(origin_class.__orig_bases__[0])
104104
generic_values = get_args(class_)
105105
generic_name_value = {generic_types[i]: generic_values[i] for i in range(len(generic_types))}
106106
for k, v in annotations.items():
107107
annotations[k] = generic_name_value.get(v, v)
108108
else:
109-
annotations = class_.__annotations__.copy()
109+
annotations = get_type_hints(annotations)
110110

111111
additional_annotations = ADDITIONAL_ANNOTATIONS.get(class_, {})
112112
annotations = {**annotations, **additional_annotations}

0 commit comments

Comments
 (0)