Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gh-104683: Argument clinic: Minor readability improvements for Destination.__init__ #106652

Merged
merged 1 commit into from
Jul 11, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions Tools/clinic/clinic.py
Original file line number Diff line number Diff line change
Expand Up @@ -1959,14 +1959,19 @@ def __init__(self, name, type, clinic, *args):
self.name = name
self.type = type
self.clinic = clinic
self.buffers = BufferSeries()

valid_types = ('buffer', 'file', 'suppress')
if type not in valid_types:
fail("Invalid destination type " + repr(type) + " for " + name + " , must be " + ', '.join(valid_types))
fail(
f"Invalid destination type {type!r} for {name}, "
f"must be {', '.join(valid_types)}"
)
extra_arguments = 1 if type == "file" else 0
if len(args) < extra_arguments:
fail("Not enough arguments for destination " + name + " new " + type)
fail(f"Not enough arguments for destination {name} new {type}")
if len(args) > extra_arguments:
fail("Too many arguments for destination " + name + " new " + type)
fail(f"Too many arguments for destination {name} new {type}")
if type =='file':
d = {}
filename = clinic.filename
Expand All @@ -1979,8 +1984,6 @@ def __init__(self, name, type, clinic, *args):
d['basename_root'], d['basename_extension'] = os.path.splitext(filename)
self.filename = args[0].format_map(d)

self.buffers = BufferSeries()

def __repr__(self):
if self.type == 'file':
file_repr = " " + repr(self.filename)
Expand Down
Loading