MCPcopy Index your code
hub / github.com/PyGithub/PyGithub / _makeUnionClassAttributeFromTypeName

Method _makeUnionClassAttributeFromTypeName

github/GithubObject.py:373–391  ·  view source on GitHub ↗
(
        self, type_name: str | None, fallback_type: str | None, value: Any, *class_and_names: tuple[type[T_gh], str]
    )

Source from the content-addressed store, hash-verified

371 )
372
373 def _makeUnionClassAttributeFromTypeName(
374 self, type_name: str | None, fallback_type: str | None, value: Any, *class_and_names: tuple[type[T_gh], str]
375 ) -> Attribute[T_gh]:
376 if value is None or type_name is None:
377 return _ValuedAttribute(None) # type: ignore
378 fallback_class = None
379 for klass, name in class_and_names:
380 if type_name == name:
381 return self._makeClassAttribute(klass, value)
382 if fallback_type == name:
383 fallback_class = klass
384 if fallback_type is not None:
385 if fallback_class is None:
386 # this is misconfiguration in PyGithub code, not a user's fault
387 raise ValueError(
388 f"Fallback type {fallback_type} is not among classes and names: {[name for klass, name in class_and_names]}"
389 )
390 return self._makeClassAttribute(fallback_class, value)
391 return _BadAttribute(value, type) # type: ignore
392
393 def _makeUnionClassAttributeFromTypeKey(
394 self,

Calls 3

_makeClassAttributeMethod · 0.95
_ValuedAttributeClass · 0.85
_BadAttributeClass · 0.85

Tested by

no test coverage detected