Skip to content

Commit 5bee260

Browse files
committed
treewide: fix B904
1 parent 2c617aa commit 5bee260

8 files changed

Lines changed: 9 additions & 10 deletions

File tree

devel/management/commands/reporead.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -601,7 +601,7 @@ def locate_arch(arch):
601601
try:
602602
return Arch.objects.get(name=arch)
603603
except Arch.DoesNotExist:
604-
raise CommandError('Specified architecture %s is not currently known.' % arch)
604+
raise CommandError("Specified architecture %s is not currently known." % arch) from None
605605

606606

607607
def read_repo(primary_arch, repo_file, options):

devel/management/commands/retire_user.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,12 @@ def handle(self, *args, **options):
4444
try:
4545
user = User.objects.get(username=options['user'])
4646
except User.DoesNotExist:
47-
raise CommandError(u"Failed to find User '{}'".format(options['user']))
47+
raise CommandError("Failed to find User '{}'".format(options["user"])) from None
4848

4949
try:
5050
profile = UserProfile.objects.get(user=user)
5151
except UserProfile.DoesNotExist:
52-
raise CommandError(u"Failed to find UserProfile")
52+
raise CommandError("Failed to find UserProfile") from None
5353

5454
# Set user inactive
5555
user.is_active = False

mirrors/fields.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ def to_python(self, value):
1212
try:
1313
value = IP(value)
1414
except ValueError as e:
15-
raise ValidationError(str(e))
15+
raise ValidationError(str(e)) from e
1616
return value
1717

1818

mirrors/models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ def clean(self):
103103
protocol = urlparse(self.url).scheme
104104
self.protocol = MirrorProtocol.objects.get(protocol=protocol)
105105
except Exception as e:
106-
raise ValidationError(e)
106+
raise ValidationError(e) from e
107107
try:
108108
families = self.address_families()
109109
self.has_ipv4 = socket.AF_INET in families

packages/templatetags/package_extras.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ def render(self, context):
2727
def do_buildsortqs(parser, token):
2828
try:
2929
_, sortfield = token.split_contents()
30-
except ValueError:
31-
raise template.TemplateSyntaxError("%r tag requires a single argument" % token)
30+
except ValueError as exc:
31+
raise template.TemplateSyntaxError("%r tag requires a single argument" % token) from exc
3232
if not (sortfield[0] == sortfield[-1] and sortfield[0] in ('"', "'")):
3333
raise template.TemplateSyntaxError("%r tag's argument should be in quotes" % token)
3434
return BuildQueryStringNode(sortfield[1:-1])

packages/views/display.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ def details(request, name='', repo='', arch=''):
148148
if ret:
149149
return ret
150150
# we've tried everything at this point, nothing to see
151-
raise Http404
151+
raise Http404 from None
152152
else:
153153
return redirect_to_search(request, name, repo, arch)
154154

packages/views/signoff.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def signoff_package(request, name, repo, arch, revoke=False):
4646
try:
4747
signoff = Signoff.objects.get_from_package(package, request.user, False)
4848
except Signoff.DoesNotExist:
49-
raise Http404
49+
raise Http404 from None
5050
signoff.revoked = now()
5151
signoff.save(update_fields=('revoked',))
5252
created = False

pyproject.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ select = [
7575

7676
ignore = [
7777
"E731", # Do not assign a `lambda` expression, use a `def`
78-
"B904", # Within an `except` clause, raise exceptions with `raise ... from err`
7978
"RUF012", # Mutable class attributes should be annotated with `typing.ClassVar`
8079
# TODO: add these one by one
8180
"DJ001", # Avoid using `null=True` on string-based fields such as `CharField`

0 commit comments

Comments
 (0)