MCPcopy
hub / github.com/celery/celery / annotation_is_class

Function annotation_is_class

celery/utils/annotations.py:37–44  ·  view source on GitHub ↗

Test if a given annotation is a class that can be used in isinstance()/issubclass().

(annotation: typing.Any)

Source from the content-addressed store, hash-verified

35
36
37def annotation_is_class(annotation: typing.Any) -> bool:
38 """Test if a given annotation is a class that can be used in isinstance()/issubclass()."""
39 # isclass() returns True for generic type hints (e.g. `list[str]`) until Python 3.10.
40 # NOTE: The guard for Python 3.9 is because types.GenericAlias is only added in Python 3.9. This is not a problem
41 # as the syntax is added in the same version in the first place.
42 if (3, 9) <= sys.version_info < (3, 11) and isinstance(annotation, types.GenericAlias):
43 return False
44 return isclass(annotation)
45
46
47def annotation_issubclass(annotation: typing.Any, cls: type) -> bool:

Callers 2

annotation_issubclassFunction · 0.85
wrapperFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected