Skip to content

Commit

Permalink
Type str/repr dunders (#4582)
Browse files Browse the repository at this point in the history
Co-authored-by: Anderson Bravalheri <andersonbravalheri@gmail.com>
  • Loading branch information
Avasam and abravalheri authored Aug 27, 2024
1 parent d12330d commit 2d63f5c
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
14 changes: 7 additions & 7 deletions pkg_resources/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ def get_supported_platform():
class ResolutionError(Exception):
"""Abstract base for dependency resolution errors"""

def __repr__(self):
def __repr__(self) -> str:
return self.__class__.__name__ + repr(self.args)


Expand Down Expand Up @@ -377,7 +377,7 @@ def requirers_str(self):
def report(self):
return self._template.format(**locals())

def __str__(self):
def __str__(self) -> str:
return self.report()


Expand Down Expand Up @@ -2725,15 +2725,15 @@ def __init__(
self.extras = tuple(extras)
self.dist = dist

def __str__(self):
def __str__(self) -> str:
s = "%s = %s" % (self.name, self.module_name)
if self.attrs:
s += ':' + '.'.join(self.attrs)
if self.extras:
s += ' [%s]' % ','.join(self.extras)
return s

def __repr__(self):
def __repr__(self) -> str:
return "EntryPoint.parse(%r)" % str(self)

@overload
Expand Down Expand Up @@ -3157,13 +3157,13 @@ def egg_name(self):
filename += '-' + self.platform
return filename

def __repr__(self):
def __repr__(self) -> str:
if self.location:
return "%s (%s)" % (self, self.location)
else:
return str(self)

def __str__(self):
def __str__(self) -> str:
try:
version = getattr(self, 'version', None)
except ValueError:
Expand Down Expand Up @@ -3508,7 +3508,7 @@ def __contains__(
def __hash__(self):
return self.__hash

def __repr__(self):
def __repr__(self) -> str:
return "Requirement.parse(%r)" % str(self)

@staticmethod
Expand Down
2 changes: 1 addition & 1 deletion setuptools/sandbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,6 @@ class SandboxViolation(DistutilsError):
"""
).lstrip()

def __str__(self):
def __str__(self) -> str:
cmd, args, kwargs = self.args
return self.tmpl.format(**locals())
2 changes: 1 addition & 1 deletion setuptools/tests/test_sandbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def test_unpickleable_exception(self):
class CantPickleThis(Exception):
"This Exception is unpickleable because it's not in globals"

def __repr__(self):
def __repr__(self) -> str:
return 'CantPickleThis%r' % (self.args,)

with setuptools.sandbox.ExceptionSaver() as saved_exc:
Expand Down
2 changes: 1 addition & 1 deletion setuptools/tests/test_wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ def __init__(self, id, **kwargs):
self._id = id
self._fields = kwargs

def __repr__(self):
def __repr__(self) -> str:
return '%s(**%r)' % (self._id, self._fields)


Expand Down

0 comments on commit 2d63f5c

Please sign in to comment.