@@ -728,7 +728,7 @@ def call_annotate_function(annotate, format, *, owner=None, _is_evaluate=False):
728728 annotate , owner , is_class , globals , allow_evaluation = False
729729 )
730730 func = types .FunctionType (
731- _get_annotate_attr (annotate , "__code__" , None ),
731+ _get_annotate_attr (annotate , "__code__" ),
732732 globals ,
733733 closure = closure ,
734734 argdefs = _get_annotate_attr (annotate , "__defaults__" , None ),
@@ -763,7 +763,7 @@ def call_annotate_function(annotate, format, *, owner=None, _is_evaluate=False):
763763 # Grab and store all the annotate function attributes that we might need to access
764764 # multiple times as variables, as this could be a bit expensive for non-functions.
765765 annotate_globals = _get_annotate_attr (annotate , "__globals__" , {})
766- annotate_code = _get_annotate_attr (annotate , "__code__" , None )
766+ annotate_code = _get_annotate_attr (annotate , "__code__" )
767767 annotate_defaults = _get_annotate_attr (annotate , "__defaults__" , None )
768768 annotate_kwdefaults = _get_annotate_attr (annotate , "__kwdefaults__" , None )
769769 namespace = {
@@ -890,7 +890,7 @@ def _stringify_single(anno):
890890 return repr (anno )
891891
892892
893- def _get_annotate_attr (annotate , attr , default ):
893+ def _get_annotate_attr (annotate , attr , default = _sentinel ):
894894 # Try to get the attr on the annotate function. If it doesn't exist, we might
895895 # need to look in other places on the object. If all of those fail, we can
896896 # return the default at the end.
@@ -944,6 +944,8 @@ def _get_annotate_attr(annotate, attr, default):
944944 ):
945945 return _get_annotate_attr (annotate .func , attr , default )
946946
947+ if default is _sentinel :
948+ raise TypeError (f"annotate function missing { attr !r} attribute" )
947949 return default
948950
949951def _direct_call_annotate (func , annotate , * args ):
0 commit comments