Skip to content

Commit 2867397

Browse files
committed
TYP: Annotate unknown attributes for Recoders
1 parent b3c3472 commit 2867397

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

nibabel/volumeutils.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
import gzip
1313
import sys
14+
import typing as ty
1415
import warnings
1516
from collections import OrderedDict
1617
from functools import reduce
@@ -121,6 +122,13 @@ def __init__(self, codes, fields=('code',), map_maker=OrderedDict):
121122
self.field1 = self.__dict__[fields[0]]
122123
self.add_codes(codes)
123124

125+
def __getattr__(self, key: str) -> ty.Mapping:
126+
# By setting this, we let static analyzers know that dynamic attributes will
127+
# be dict-like (Mapping).
128+
# However, __getattr__ is called if looking up the field in __dict__ fails,
129+
# so we only get here if the attribute is really missing.
130+
raise AttributeError(f'{self.__class__.__name__!r} object has no attribute {key!r}')
131+
124132
def add_codes(self, code_syn_seqs):
125133
"""Add codes to object
126134

0 commit comments

Comments
 (0)