@@ -162,19 +162,6 @@ def add_imports(
162162 ]
163163
164164
165- def remove_imports (
166- partitions : Iterable [CodePartition ],
167- to_remove : set [tuple [str , str | None ] | tuple [str , str , str | None ]],
168- ) -> list [CodePartition ]:
169- return [
170- partition for partition in partitions
171- if (
172- partition .code_type is not CodeType .IMPORT or
173- import_obj_from_str (partition .src ).key not in to_remove
174- )
175- ]
176-
177-
178165class Replacements (NamedTuple ):
179166 # (orig_mod, attr) => new_mod
180167 exact : dict [tuple [str , str ], str ]
@@ -289,16 +276,18 @@ def _module_to_base_modules(s: str) -> Generator[str, None, None]:
289276
290277def remove_duplicated_imports (
291278 partitions : Iterable [CodePartition ],
279+ * ,
280+ to_remove : set [tuple [str , ...]],
292281) -> list [CodePartition ]:
293- seen : set [ Import | ImportFrom ] = set ()
282+ seen = set (to_remove )
294283 seen_module_names : set [str ] = set ()
295284 without_exact_duplicates = []
296285
297286 for partition in partitions :
298287 if partition .code_type is CodeType .IMPORT :
299288 import_obj = import_obj_from_str (partition .src )
300- if import_obj not in seen :
301- seen .add (import_obj )
289+ if import_obj . key not in seen :
290+ seen .add (import_obj . key )
302291 if (
303292 isinstance (import_obj , Import ) and
304293 not import_obj .key .asname
@@ -385,7 +374,7 @@ def fix_file_contents(
385374 contents : str ,
386375 * ,
387376 to_add : tuple [str , ...] = (),
388- to_remove : set [tuple [str , str | None ] | tuple [ str , str , str | None ]],
377+ to_remove : set [tuple [str , ... ]],
389378 to_replace : Replacements ,
390379 settings : Settings = Settings (),
391380) -> str :
@@ -401,9 +390,8 @@ def fix_file_contents(
401390 partitioned = combine_trailing_code_chunks (partitioned )
402391 partitioned = add_imports (partitioned , to_add = to_add )
403392 partitioned = separate_comma_imports (partitioned )
404- partitioned = remove_imports (partitioned , to_remove = to_remove )
405393 partitioned = replace_imports (partitioned , to_replace = to_replace )
406- partitioned = remove_duplicated_imports (partitioned )
394+ partitioned = remove_duplicated_imports (partitioned , to_remove = to_remove )
407395 partitioned = apply_import_sorting (partitioned , settings = settings )
408396
409397 return _partitions_to_src (partitioned ).replace ('\n ' , nl )
@@ -413,7 +401,7 @@ def _fix_file(
413401 filename : str ,
414402 args : argparse .Namespace ,
415403 * ,
416- to_remove : set [tuple [str , str | None ] | tuple [ str , str , str | None ]],
404+ to_remove : set [tuple [str , ... ]],
417405 to_replace : Replacements ,
418406 settings : Settings = Settings (),
419407) -> int :
0 commit comments