diff --git a/pyasn1/compat/octets.py b/pyasn1/compat/octets.py index 4fcb06dc..81d7b4b9 100644 --- a/pyasn1/compat/octets.py +++ b/pyasn1/compat/octets.py @@ -9,7 +9,7 @@ if version_info[0] <= 2: int2oct = chr # noinspection PyPep8 - ints2octs = lambda s: ''.join([int2oct(x) for x in s]) + ints2octs = lambda s: ''.join(int2oct(x) for x in s) null = '' oct2int = ord # TODO: refactor to return a sequence of ints diff --git a/pyasn1/type/char.py b/pyasn1/type/char.py index 58fffb98..68d0945e 100644 --- a/pyasn1/type/char.py +++ b/pyasn1/type/char.py @@ -77,7 +77,7 @@ def prettyIn(self, value): elif isinstance(value, str): return value.decode(self.encoding) elif isinstance(value, (tuple, list)): - return self.prettyIn(''.join([chr(x) for x in value])) + return self.prettyIn(''.join(chr(x) for x in value)) elif isinstance(value, univ.OctetString): return value.asOctets().decode(self.encoding) else: @@ -94,7 +94,7 @@ def asOctets(self, padding=True): return str(self) def asNumbers(self, padding=True): - return tuple([ord(x) for x in str(self)]) + return tuple(ord(x) for x in str(self)) else: def __str__(self): diff --git a/pyasn1/type/namedtype.py b/pyasn1/type/namedtype.py index 03aec474..a4b88136 100644 --- a/pyasn1/type/namedtype.py +++ b/pyasn1/type/namedtype.py @@ -160,20 +160,19 @@ def __init__(self, *namedTypes, **kwargs): self.__ambiguousTypes = 'terminal' not in kwargs and self.__computeAmbiguousTypes() or {} self.__uniqueTagMap = self.__computeTagMaps(unique=True) self.__nonUniqueTagMap = self.__computeTagMaps(unique=False) - self.__hasOptionalOrDefault = any([True for namedType in self.__namedTypes - if namedType.isDefaulted or namedType.isOptional]) - self.__hasOpenTypes = any([True for namedType in self.__namedTypes - if namedType.openType]) + self.__hasOptionalOrDefault = any(namedType.isDefaulted or namedType.isOptional + for namedType in self.__namedTypes) + self.__hasOpenTypes = any(namedType.openType for namedType in self.__namedTypes) self.__requiredComponents = frozenset( - [idx for idx, nt in enumerate(self.__namedTypes) if not nt.isOptional and not nt.isDefaulted] + idx for idx, nt in enumerate(self.__namedTypes) if not nt.isOptional and not nt.isDefaulted ) - self.__keys = frozenset([namedType.name for namedType in self.__namedTypes]) - self.__values = tuple([namedType.asn1Object for namedType in self.__namedTypes]) - self.__items = tuple([(namedType.name, namedType.asn1Object) for namedType in self.__namedTypes]) + self.__keys = frozenset(namedType.name for namedType in self.__namedTypes) + self.__values = tuple(namedType.asn1Object for namedType in self.__namedTypes) + self.__items = tuple((namedType.name, namedType.asn1Object) for namedType in self.__namedTypes) def __repr__(self): - representation = ', '.join(['%r' % x for x in self.__namedTypes]) + representation = ', '.join('%r' % x for x in self.__namedTypes) return '<%s object, types %s>' % ( self.__class__.__name__, representation) diff --git a/pyasn1/type/namedval.py b/pyasn1/type/namedval.py index ef177ca3..76049d36 100644 --- a/pyasn1/type/namedval.py +++ b/pyasn1/type/namedval.py @@ -104,7 +104,7 @@ def __init__(self, *args, **kwargs): number += 1 def __repr__(self): - representation = ', '.join(['%s=%d' % x for x in self.items()]) + representation = ', '.join('%s=%d' % x for x in self.items()) if len(representation) > 64: representation = representation[:32] + '...' + representation[-32:] diff --git a/pyasn1/type/tag.py b/pyasn1/type/tag.py index 6ac04c38..b987337f 100644 --- a/pyasn1/type/tag.py +++ b/pyasn1/type/tag.py @@ -194,8 +194,8 @@ def __init__(self, baseTag=(), *superTags): self.__hash = hash(self.__superTagsClassId) def __repr__(self): - representation = '-'.join(['%s:%s:%s' % (x.tagClass, x.tagFormat, x.tagId) - for x in self.__superTags]) + representation = '-'.join('%s:%s:%s' % (x.tagClass, x.tagFormat, x.tagId) + for x in self.__superTags) if representation: representation = 'tags ' + representation else: diff --git a/pyasn1/type/univ.py b/pyasn1/type/univ.py index 488241fd..bff802bd 100644 --- a/pyasn1/type/univ.py +++ b/pyasn1/type/univ.py @@ -703,7 +703,7 @@ def prettyIn(self, value): return self.fromBinaryString(value, internalFormat=True) elif isinstance(value, (tuple, list)): - return self.fromBinaryString(''.join([b and '1' or '0' for b in value]), internalFormat=True) + return self.fromBinaryString(''.join(b and '1' or '0' for b in value), internalFormat=True) elif isinstance(value, BitString): return SizedInteger(value).setBitLength(len(value)) @@ -839,7 +839,7 @@ def prettyIn(self, value): elif isinstance(value, (tuple, list)): try: - return ''.join([chr(x) for x in value]) + return ''.join(chr(x) for x in value) except ValueError: raise error.PyAsn1Error( @@ -867,7 +867,7 @@ def asOctets(self): return str(self._value) def asNumbers(self): - return tuple([ord(x) for x in self._value]) + return tuple(ord(x) for x in self._value) else: def prettyIn(self, value): @@ -1221,14 +1221,14 @@ def prettyIn(self, value): 'Malformed Object ID %s at %s: %s' % (value, self.__class__.__name__, sys.exc_info()[1]) ) try: - return tuple([int(subOid) for subOid in value.split('.') if subOid]) + return tuple(int(subOid) for subOid in value.split('.') if subOid) except ValueError: raise error.PyAsn1Error( 'Malformed Object ID %s at %s: %s' % (value, self.__class__.__name__, sys.exc_info()[1]) ) try: - tupleOfInts = tuple([int(subOid) for subOid in value if subOid >= 0]) + tupleOfInts = tuple(int(subOid) for subOid in value if subOid >= 0) except (ValueError, TypeError): raise error.PyAsn1Error( @@ -1241,7 +1241,7 @@ def prettyIn(self, value): raise error.PyAsn1Error('Malformed Object ID %s at %s' % (value, self.__class__.__name__)) def prettyOut(self, value): - return '.'.join([str(x) for x in value]) + return '.'.join(str(x) for x in value) class Real(base.SimpleAsn1Type):