dflook / python-minifier

Transform Python source code into its most compact representation
MIT License
558 stars 41 forks source link

Cannot turn off - Hoist Literals #4

Closed fizista closed 4 years ago

fizista commented 4 years ago

As in the title you can not turn off, see below:

>>> pyminify --no-hoist-literals - 

def validate(arn, props):
    if 'ValidationMethod' in props and props['ValidationMethod'] == 'DNS':

        all_records_created = False
        while not all_records_created:
            all_records_created = True

            certificate = acm.describe_certificate(CertificateArn=arn)['Certificate']

            if certificate['Status'] != 'PENDING_VALIDATION':
                return

            for v in certificate['DomainValidationOptions']:

                if 'ValidationStatus' not in v or 'ResourceRecord' not in v:
                    all_records_created = False
                    continue

                records = []
                if v['ValidationStatus'] == 'PENDING_VALIDATION':
                    records.append({
                        'Action': 'UPSERT',
                        'ResourceRecordSet': {
                            'Name': v['ResourceRecord']['Name'],
                            'Type': v['ResourceRecord']['Type'],
                            'TTL': 60,
                            'ResourceRecords': [{
                                'Value': v['ResourceRecord']['Value']
                            }]
                        }
                    })

                if records:
                    response = boto3.client('route53').change_resource_record_sets(
                        HostedZoneId=get_zone_for(v['DomainName'], props),
                        ChangeBatch={
                            'Comment': 'Domain validation for %s' % arn,
                            'Changes': records
                        }
                    )
def validate(arn,props):
        B=props
        if'ValidationMethod'in B and B['ValidationMethod']=='DNS':
                C=False
                while not C:
                        C=True;E=acm.describe_certificate(CertificateArn=arn)['Certificate']
                        if E['Status']!='PENDING_VALIDATION':return
                        for A in E['DomainValidationOptions']:
                                if'ValidationStatus'not in A or'ResourceRecord'not in A:C=False;continue
                                D=[]
                                if A['ValidationStatus']=='PENDING_VALIDATION':D.append({'Action':'UPSERT','ResourceRecordSet':{'Name':A['ResourceRecord']['Name'],'Type':A['ResourceRecord']['Type'],'TTL':60,'ResourceRecords':[{'Value':A['ResourceRecord']['Value']}]}})
                                if D:F=boto3.client('route53').change_resource_record_sets(HostedZoneId=get_zone_for(A['DomainName'],B),ChangeBatch={'Comment':'Domain validation for %s'%arn,'Changes':D})
dflook commented 4 years ago

Hi, thanks for creating an issue.

In this example the --no-hoist-literals option appears to be working as intended. Which part doesn't look right?