(self, tx, name)
| 161 | ) |
| 162 | |
| 163 | def var_getattr(self, tx, name): |
| 164 | from .builder import VariableBuilder |
| 165 | |
| 166 | if self.source: |
| 167 | source = AttrSource(self.source, name) |
| 168 | else: |
| 169 | source = None |
| 170 | |
| 171 | base = tx.output.get_submodule(self.module_key) |
| 172 | base_dict = object.__getattribute__(base, "__dict__") |
| 173 | object_member = True |
| 174 | all_class_attribute_names = set() |
| 175 | for x in inspect.getmro(base.__class__): |
| 176 | all_class_attribute_names.update(x.__dict__.keys()) |
| 177 | |
| 178 | if not self.source: |
| 179 | unimplemented("GETATTR with no source") |
| 180 | |
| 181 | if name in base_dict: |
| 182 | subobj = base_dict[name] |
| 183 | elif ( |
| 184 | "_modules" in base_dict |
| 185 | and name in base_dict["_modules"] |
| 186 | and name not in all_class_attribute_names |
| 187 | ): |
| 188 | subobj = base_dict["_modules"][name] |
| 189 | elif "_parameters" in base_dict and name in base_dict["_parameters"]: |
| 190 | subobj = base_dict["_parameters"][name] |
| 191 | elif "_buffers" in base_dict and name in base_dict["_buffers"]: |
| 192 | subobj = base_dict["_buffers"][name] |
| 193 | else: |
| 194 | try: |
| 195 | subobj = inspect.getattr_static(base, name) |
| 196 | object_member = False |
| 197 | except AttributeError: |
| 198 | # see if we can fallback to __getattr__, which is not checked by getattr_static |
| 199 | result = self._custom_getattr_fallback( |
| 200 | base=base, tx=tx, name=name, options={"source": source} |
| 201 | ) |
| 202 | if result is not None: |
| 203 | return result |
| 204 | # if we can't find a __getattr__, just raise the AttributeError |
| 205 | raise |
| 206 | |
| 207 | if name == "__class__" and not object_member: |
| 208 | return variables.UserDefinedClassVariable(base.__class__, source=source) |
| 209 | |
| 210 | if object_member: |
| 211 | return VariableBuilder(tx, NNModuleSource(source))(subobj) |
| 212 | else: |
| 213 | if istype(subobj, property): |
| 214 | return variables.UserFunctionVariable( |
| 215 | subobj.fget, |
| 216 | source=source, |
| 217 | ).call_function(tx, [(self)], {}) |
| 218 | elif istype(subobj, classmethod): |
| 219 | return variables.UserMethodVariable( |
| 220 | subobj.__func__, |
nothing calls this directly
no test coverage detected