@@ -897,9 +897,7 @@ def _extract_init_attributes(class_node: ast.ClassDef, context: EvaluationContex
897897 # Evaluate the assigned value
898898 value = eval_node (stmt .value , temp_context )
899899 if value is not None and value is not NOT_EVALUATED :
900- inferred_type = _create_duck_from_value (value )
901- if inferred_type is not None :
902- attributes [attr_name ] = inferred_type
900+ attributes [attr_name ] = value
903901 except Exception :
904902 # Skip the attribute
905903 pass
@@ -929,44 +927,13 @@ def _extract_init_attributes(class_node: ast.ClassDef, context: EvaluationContex
929927 try :
930928 value = eval_node (stmt .value , temp_context )
931929 if value is not None and value is not NOT_EVALUATED :
932- inferred_type = _create_duck_from_value (value )
933- if inferred_type is not None :
934- attributes [attr_name ] = inferred_type
930+ attributes [attr_name ] = value
935931 except Exception :
936932 pass
937933
938934 return attributes
939935
940936
941- def _create_duck_from_value (value ):
942- """Create a Duck object from an actual runtime value."""
943- if value is None or value is NOT_EVALUATED :
944- return None
945- value_type = type (value )
946- if isinstance (value , dict ):
947- return _Duck (
948- attributes = dict .fromkeys (dir (dict ())), items = value if value else {}
949- )
950- elif isinstance (value , list ):
951- element_duck = None
952- if value :
953- element_duck = _create_duck_from_value (value [0 ])
954- return _Duck (
955- attributes = dict .fromkeys (dir (list ())),
956- items = _GetItemDuck (lambda : element_duck ),
957- )
958- elif isinstance (value , set ):
959- return _Duck (attributes = dict .fromkeys (dir (set ())))
960- elif isinstance (value , tuple ):
961- return value
962- elif isinstance (value , (str , int , float , bool , bytes )):
963- return _Duck (attributes = dict .fromkeys (dir (value_type ())))
964- else :
965- try :
966- return _create_duck_for_heap_type (value_type )
967- except Exception :
968- return _Duck (attributes = dict .fromkeys (dir (value )))
969-
970937def _eval_return_type (func : Callable , node : ast .Call , context : EvaluationContext ):
971938 """Evaluate return type of a given callable function.
972939
0 commit comments