Changeset 9348:f14c8405934e in orange


Ignore:
Timestamp:
12/13/11 15:25:50 (2 years ago)
Author:
markotoplak
Branch:
default
Convert:
506f91ada1442b4f0e1f51a7a6aae1f3f6cc5b97
Message:

Fixed previous commit to copy the prefix, so that the comments do not get lost.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • orange/fixes/fix_orange_top_import.py

    r9346 r9348  
    2828class FixOrangeTopImport(fixer_base.BaseFix): 
    2929 
    30     PATTERN = """ 
    31     import_name< 'import' imp=any > 
    32     """ 
     30    PATTERN = """import_name< 'import' imp=any >""" 
    3331 
    3432    run_order = 7 
     
    5553                handle_one(imp) 
    5654     
    57             #FIXME remove newlines that remained from these import statements 
    58             return Import(new_contents) if new_contents else BlankLine() 
     55            #copy prefix, so you do not lose comments 
     56            opref = node.prefix 
     57            if new_contents: 
     58                nn = Import(new_contents) 
     59                nn.prefix = opref 
     60            else: 
     61                nn = BlankLine() 
     62                if opref and opref[-1] in ["\n"]: #remove previous newline 
     63                    opref = opref[:-1] 
     64                nn.prefix = opref 
     65         
     66            return nn 
    5967 
    6068        return t(imp) 
Note: See TracChangeset for help on using the changeset viewer.