Missing annotations#
When we are defining our own objects, we can always annotate them and allow TkClassWizard to work without any problems. Unfortunately other (including Python’s built-in) libraries may not have types annotated inside their classes and functions. If we wish to use those libraries and graphically define objects with TkClassWizard, we will have problems.
To solve the issue of missing annotations, TkClassWizard contains an annotations module for dealing with missing annotations.
If you feel the need to register additional class annotations, you can do so with the
register_annotations() function.
This function accepts the class as an input and a set of keyword arguments which which map parameter=datatype.
Example is shown below.
1from tkclasswiz.annotations import register_annotations
2
3class MissingAnnotations:
4 def __init__(self, a, b, c):
5 ...
6
7register_annotations(
8 MissingAnnotations,
9 a=int,
10 b=float,
11 c=str
12)
For convenience datetime.datetime, datetime.timedelta and datetime.timezone already
have these annotations registered.
To obtain a mapping of registered annotations, get_annotations() can be used.
It returns a dictionary mapping parameter to the data type for both code defined annotations and annotations defined
with register_annotations().