From 5a5e096520d6ee42b99abaa724e16a48c10f261d Mon Sep 17 00:00:00 2001 From: Ilya Etingof Date: Sat, 13 Jul 2019 11:47:45 +0200 Subject: Remove Python `id` from `repr` It seems to clutter representation printout, especially in the rendered docs. --- pyasn1/type/base.py | 19 +++++++++---------- pyasn1/type/constraint.py | 5 +++-- pyasn1/type/namedtype.py | 8 +++++--- pyasn1/type/namedval.py | 3 ++- pyasn1/type/tag.py | 8 +++++--- pyasn1/type/tagmap.py | 8 ++++---- 6 files changed, 28 insertions(+), 23 deletions(-) (limited to 'pyasn1') diff --git a/pyasn1/type/base.py b/pyasn1/type/base.py index 61ec35e..626e638 100644 --- a/pyasn1/type/base.py +++ b/pyasn1/type/base.py @@ -222,7 +222,7 @@ class NoValue(object): raise error.PyAsn1Error('Attempted "%s" operation on ASN.1 schema object' % attr) def __repr__(self): - return '<%s object at 0x%x>' % (self.__class__.__name__, id(self)) + return '<%s object>' % self.__class__.__name__ noValue = NoValue() @@ -249,19 +249,18 @@ class AbstractSimpleAsn1Item(Asn1ItemBase): self._value = value def __repr__(self): - representation = '%s %s object at 0x%x' % ( - self.__class__.__name__, self.isValue and 'value' or 'schema', id(self) - ) + representation = '%s %s object' % ( + self.__class__.__name__, self.isValue and 'value' or 'schema') for attr, value in self.readOnly.items(): if value: - representation += ' %s %s' % (attr, value) + representation += ', %s %s' % (attr, value) if self.isValue: value = self.prettyPrint() if len(value) > 32: value = value[:16] + '...' + value[-16:] - representation += ' payload [%s]' % value + representation += ', payload [%s]' % value return '<%s>' % representation @@ -469,16 +468,16 @@ class AbstractConstructedAsn1Item(Asn1ItemBase): Asn1ItemBase.__init__(self, **readOnly) def __repr__(self): - representation = '%s %s object at 0x%x' % ( - self.__class__.__name__, self.isValue and 'value' or 'schema', id(self) + representation = '%s %s object' % ( + self.__class__.__name__, self.isValue and 'value' or 'schema' ) for attr, value in self.readOnly.items(): if value is not noValue: - representation += ' %s=%r' % (attr, value) + representation += ', %s=%r' % (attr, value) if self.isValue and self.components: - representation += ' payload [%s]' % ', '.join( + representation += ', payload [%s]' % ', '.join( [repr(x) for x in self.components]) return '<%s>' % representation diff --git a/pyasn1/type/constraint.py b/pyasn1/type/constraint.py index 656e203..807c827 100644 --- a/pyasn1/type/constraint.py +++ b/pyasn1/type/constraint.py @@ -37,10 +37,11 @@ class AbstractConstraint(object): ) def __repr__(self): - representation = '%s object at 0x%x' % (self.__class__.__name__, id(self)) + representation = '%s object' % (self.__class__.__name__) if self._values: - representation += ' consts %s' % ', '.join([repr(x) for x in self._values]) + representation += ', consts %s' % ', '.join( + [repr(x) for x in self._values]) return '<%s>' % representation diff --git a/pyasn1/type/namedtype.py b/pyasn1/type/namedtype.py index 936c96c..cbc1429 100644 --- a/pyasn1/type/namedtype.py +++ b/pyasn1/type/namedtype.py @@ -49,9 +49,10 @@ class NamedType(object): representation = '%s=%r' % (self.name, self.asn1Object) if self.openType: - representation += ' openType: %r' % self.openType + representation += ', open type %r' % self.openType - return '<%s object at 0x%x type %s>' % (self.__class__.__name__, id(self), representation) + return '<%s object, type %s>' % ( + self.__class__.__name__, representation) def __eq__(self, other): return self.__nameAndType == other @@ -173,7 +174,8 @@ class NamedTypes(object): def __repr__(self): representation = ', '.join(['%r' % x for x in self.__namedTypes]) - return '<%s object at 0x%x types %s>' % (self.__class__.__name__, id(self), representation) + return '<%s object, types %s>' % ( + self.__class__.__name__, representation) def __eq__(self, other): return self.__namedTypes == other diff --git a/pyasn1/type/namedval.py b/pyasn1/type/namedval.py index 40468d4..4247597 100644 --- a/pyasn1/type/namedval.py +++ b/pyasn1/type/namedval.py @@ -109,7 +109,8 @@ class NamedValues(object): if len(representation) > 64: representation = representation[:32] + '...' + representation[-32:] - return '<%s object 0x%x enums %s>' % (self.__class__.__name__, id(self), representation) + return '<%s object, enums %s>' % ( + self.__class__.__name__, representation) def __eq__(self, other): return dict(self) == other diff --git a/pyasn1/type/tag.py b/pyasn1/type/tag.py index b46f491..dd33e49 100644 --- a/pyasn1/type/tag.py +++ b/pyasn1/type/tag.py @@ -64,8 +64,10 @@ class Tag(object): self.__hash = hash(self.__tagClassId) def __repr__(self): - representation = '[%s:%s:%s]' % (self.__tagClass, self.__tagFormat, self.__tagId) - return '<%s object at 0x%x tag %s>' % (self.__class__.__name__, id(self), representation) + representation = '[%s:%s:%s]' % ( + self.__tagClass, self.__tagFormat, self.__tagId) + return '<%s object, tag %s>' % ( + self.__class__.__name__, representation) def __eq__(self, other): return self.__tagClassId == other @@ -199,7 +201,7 @@ class TagSet(object): else: representation = 'untagged' - return '<%s object at 0x%x %s>' % (self.__class__.__name__, id(self), representation) + return '<%s object, %s>' % (self.__class__.__name__, representation) def __add__(self, superTag): return self.__class__(self.__baseTag, *self.__superTags + (superTag,)) diff --git a/pyasn1/type/tagmap.py b/pyasn1/type/tagmap.py index e53a14d..6f5163b 100644 --- a/pyasn1/type/tagmap.py +++ b/pyasn1/type/tagmap.py @@ -56,16 +56,16 @@ class TagMap(object): return iter(self.__presentTypes) def __repr__(self): - representation = '%s object at 0x%x' % (self.__class__.__name__, id(self)) + representation = '%s object' % self.__class__.__name__ if self.__presentTypes: - representation += ' present %s' % repr(self.__presentTypes) + representation += ', present %s' % repr(self.__presentTypes) if self.__skipTypes: - representation += ' skip %s' % repr(self.__skipTypes) + representation += ', skip %s' % repr(self.__skipTypes) if self.__defaultType is not None: - representation += ' default %s' % repr(self.__defaultType) + representation += ', default %s' % repr(self.__defaultType) return '<%s>' % representation -- cgit v1.2.1