@@ -858,11 +858,6 @@ def get_func_target(builder: IRBuilder, fdef: FuncDef) -> AssignmentTarget:
858858 return builder .add_local_reg (fdef , object_rprimitive )
859859
860860
861- # This function still does not support the following imports.
862- # import json as _json
863- # from json import decoder
864- # Using either _json.JSONDecoder or decoder.JSONDecoder as a type hint for a dataclass field will fail.
865- # See issue mypyc/mypyc#1099.
866861def load_type (builder : IRBuilder , typ : TypeInfo , unbounded_type : Type | None , line : int ) -> Value :
867862 # typ.fullname contains the module where the class object was defined. However, it is possible
868863 # that the class object's module was not imported in the file currently being compiled. So, we
@@ -876,34 +871,17 @@ def load_type(builder: IRBuilder, typ: TypeInfo, unbounded_type: Type | None, li
876871 # `mod2.mod3.OuterClass.InnerClass` and `unbounded_type.name` is `mod1.OuterClass.InnerClass`.
877872 # So, we must use unbounded_type.name to load the class object.
878873 # See issue mypyc/mypyc#1087.
879- load_attr_path = (
880- unbounded_type .name if isinstance (unbounded_type , UnboundType ) else typ .fullname
881- ).removesuffix (f".{ typ .name } " )
882874 if typ in builder .mapper .type_to_ir :
883875 class_ir = builder .mapper .type_to_ir [typ ]
884876 class_obj = builder .builder .get_native_type (class_ir )
885877 elif typ .fullname in builtin_names :
886878 builtin_addr_type , src = builtin_names [typ .fullname ]
887879 class_obj = builder .add (LoadAddress (builtin_addr_type , src , line ))
888- # This elif-condition finds the longest import that matches the load_attr_path.
889- elif module_name := max (
890- (i for i in builder .imports if load_attr_path == i or load_attr_path .startswith (f"{ i } ." )),
891- default = "" ,
892- key = len ,
893- ):
894- # Load the imported module.
895- loaded_module = builder .load_module (module_name )
896- # Recursively load attributes of the imported module. These may be submodules, classes or
897- # any other object.
898- for attr in (
899- load_attr_path .removeprefix (f"{ module_name } ." ).split ("." )
900- if load_attr_path != module_name
901- else []
902- ):
903- loaded_module = builder .py_get_attr (loaded_module , attr , line )
904- class_obj = builder .builder .get_attr (
905- loaded_module , typ .name , object_rprimitive , line , borrow = False
906- )
880+ elif isinstance (unbounded_type , UnboundType ):
881+ path_parts = unbounded_type .name .split ("." )
882+ class_obj = builder .load_global_str (path_parts [0 ], line )
883+ for attr in path_parts [1 :]:
884+ class_obj = builder .py_get_attr (class_obj , attr , line )
907885 else :
908886 class_obj = builder .load_global_str (typ .name , line )
909887
0 commit comments