Skip to content

Commit 4e4e3a7

Browse files
committed
Minor updates
1 parent a20d4ef commit 4e4e3a7

2 files changed

Lines changed: 4 additions & 11 deletions

File tree

scripts/send_email.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
import os
1212
import re
1313

14-
# Install matej libraries (tested with 0.12.3): https://sclera.fri.uni-lj.si/code.html#Libraries
1514
from matej.argparse import ArgParser, StrArg
1615
from matej.web.email import send_email
1716

@@ -47,7 +46,7 @@ def parse_cli_args():
4746
ap.add_arg(EmailArg('-c', '--cc', help="CC emails (will be added on each email if sending individually)", nargs='+'))
4847
ap.add_arg(EmailArg('-b', '--bcc', help="BCC emails (will be added on each email if sending individually)", nargs='+'))
4948
ap.add_bool_arg('-i', '--send-individually', help="Send emails to each recipient separately", default=True)
50-
ap.add_number_arg('-l', '--limit', '--rate-limit', help="Rate limit (in emails per second)", nargs=1, default=None, min=0)
49+
ap.add_number_arg('-l', '--limit', '--rate-limit', help="Rate limit (in emails per second)", nargs=1, min=0)
5150
return ap.parse_args()
5251

5352

src/matej/argparse.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ class ArgParser(argparse.ArgumentParser):
2020
It also provides the `'store_dict'` action, which allows the user to pass key-value pairs as argument values.
2121
Additionally, any argument can be given a :class:`Query` instance as a default value, which will prompt the user for the argument's value if not provided. #TODO: Test this more thoroughly
2222
"""
23-
2423
def __init__(self, *args, **kw):
2524
""" Initialise the parser. See the documentation of :class:`argparse.ArgumentParser` for more information. """
2625
kw.setdefault('formatter_class', HelpfulFormatter)
@@ -117,7 +116,6 @@ class Arg(ABC):
117116
Instances of this class's subclasses can be added to an arbitrary :class:`argparse.ArgumentParser` instance
118117
using the :meth:`add_to_ap` method, although certain restrictions apply, as specified in the subclasses' docs.
119118
"""
120-
121119
def __init__(self, *flags, **kw):
122120
"""
123121
Initialise the argument.
@@ -180,9 +178,9 @@ def str(self, value):
180178
return f'{self.name_flag} {value}'
181179

182180

181+
#TODO: Figure out what to do in case of multiple args (nargs='+' or nargs='*')
183182
class NullableArg(Arg, ABC):
184183
""" Base class for arguments that may allow `None` as a valid value. """
185-
186184
def __init__(self, *flags, nullable=None, null_phrases=('', 'none'), **kw):
187185
"""
188186
Initialise the argument.
@@ -284,6 +282,7 @@ def add_to_ap(self, parser, **kw):
284282
kw = self.kw | kw
285283
dest = kw.get('dest', (self.yes_flags[0] if self.yes_flags else self.flags[0]).lstrip('-')).replace('-', '_')
286284
group = parser.add_mutually_exclusive_group()
285+
result = None
287286
if self.yes_flags:
288287
result = group.add_argument(*self.yes_flags, dest=dest, default=argparse.SUPPRESS, action='store_true', help=self.yes_help, **kw)
289288
if self.no_flags:
@@ -355,21 +354,17 @@ def __init__(self, choices, *flags, choice_descriptions=(), type=None, help="",
355354
self.kw['help'] = help
356355

357356

358-
#TODO: Make nullable (?) -- what do I do with multiple values in that case? One of them can be None or the entire tuple can be None?
357+
#TODO: Make nullable
359358
class NumberArg(Arg):
360359
""" Number argument. """
361360
def __init__(self, *flags, min=None, max=None, range=None, type=None, help="", **kw):
362361
"""
363362
Initialise the argument.
364363
365-
The argument can receive multiple values (if it does, they will be stored as a list). This can be explicitly restricted by passing `nargs=1` to this method.
366-
367364
Parameters
368365
----------
369366
action : str or :class:`argparse.Action`, default=ListOrSingleAction
370367
The action to use for the argument. Should most likely be left as default but can be overridden if necessary.
371-
nargs : int or str, default='+'
372-
The number of arguments to parse. See the documentation of :meth:`argparse.ArgumentParser.add_argument` for more information.
373368
min : Union[int, float], optional
374369
The minimum value the argument can have.
375370
max : Union[int, float], optional
@@ -384,7 +379,6 @@ def __init__(self, *flags, min=None, max=None, range=None, type=None, help="", *
384379
Otherwise, the auto-generated help will contain unformatted range information.
385380
"""
386381
kw.setdefault('action', ListOrSingleAction)
387-
kw.setdefault('nargs', '+')
388382
super().__init__(*flags, **kw)
389383

390384
if range is not None:

0 commit comments

Comments
 (0)