@@ -18,9 +18,8 @@ def timedelta_from_dict(r):
18
18
for k , v in r .items ():
19
19
if k == "days" :
20
20
return timedelta (days = v )
21
- raise argparse .ArgumentTypeError (
22
- f"Unknown retention period definition: { k } ={ v } "
23
- )
21
+ raise argparse .ArgumentTypeError (f"Unknown retention period definition: { k } ={ v } " )
22
+ return None
24
23
25
24
26
25
class Table :
@@ -96,32 +95,22 @@ def __new__(cls, *args):
96
95
raise argparse .ArgumentTypeError (f"{ args } is not a single argument" )
97
96
query_string = args [0 ].strip ()
98
97
if not query_string .endswith (";" ):
99
- raise argparse .ArgumentTypeError (
100
- f"[{ query_string } ] does not end with a ';'"
101
- )
98
+ raise argparse .ArgumentTypeError (f"[{ query_string } ] does not end with a ';'" )
102
99
if query_string .count (";" ) > 1 :
103
- raise argparse .ArgumentTypeError (
104
- f"[{ query_string } ] has more than one statement"
105
- )
100
+ raise argparse .ArgumentTypeError (f"[{ query_string } ] has more than one statement" )
106
101
107
102
if "?" not in query_string :
108
- raise argparse .ArgumentTypeError (
109
- f"[{ query_string } ] has no substitution variable '?'"
110
- )
103
+ raise argparse .ArgumentTypeError (f"[{ query_string } ] has no substitution variable '?'" )
111
104
if query_string .count ("?" ) > 1 :
112
105
raise argparse .ArgumentTypeError (
113
106
f"[{ query_string } ] has more than one substitution variable '?'"
114
107
)
115
108
116
109
if not query_string .upper ().startswith ("SELECT " ):
117
- raise argparse .ArgumentTypeError (
118
- f"[{ query_string } ] is not a SELECT statement"
119
- )
110
+ raise argparse .ArgumentTypeError (f"[{ query_string } ] is not a SELECT statement" )
120
111
for term in SqlQuery .forbidden_terms :
121
112
if term in query_string .upper ():
122
- raise argparse .ArgumentTypeError (
123
- f"[{ query_string } ] has a forbidden term [{ term } ]"
124
- )
113
+ raise argparse .ArgumentTypeError (f"[{ query_string } ] has a forbidden term [{ term } ]" )
125
114
126
115
return super ().__new__ (cls , query_string )
127
116
@@ -142,7 +131,7 @@ def to_sql_url(urlstring):
142
131
urltuple = urlparse (urlstring )
143
132
if urltuple .scheme .lower () != "sql" :
144
133
raise argparse .ArgumentTypeError (f"{ urlstring } is not a valid sql://" )
145
- if urltuple .path == "/" or urltuple . path == "" :
134
+ if urltuple .path in { "/" , "" } :
146
135
raise argparse .ArgumentTypeError (f"{ urlstring } should include a db path" )
147
136
return urltuple
148
137
except ValueError as ve :
@@ -259,7 +248,7 @@ def set_position(self, position_in):
259
248
"""Set the list of identifiers for this position."""
260
249
if isinstance (position_in , Position ):
261
250
self ._position = position_in .as_list ()
262
- elif isinstance (position_in , list ) or isinstance ( position_in , tuple ):
251
+ elif isinstance (position_in , ( list , tuple ) ):
263
252
self ._position = [int (p ) for p in position_in ]
264
253
else :
265
254
raise ValueError (f"Unexpected position input: { position_in } " )
@@ -345,10 +334,10 @@ def __lt__(self, other):
345
334
346
335
# If ALL of v_mine >= v_other, then self is greater than other
347
336
# If ANY of v_mine < v_other, then self is less than other
348
- for v_mine , v_other in zip ( self . _position . as_list (), other_position_list ):
349
- if v_mine < v_other :
350
- return True
351
- return False
337
+ return any (
338
+ v_mine < v_other
339
+ for v_mine , v_other in zip ( self . _position . as_list (), other_position_list )
340
+ )
352
341
353
342
def __ge__ (self , other ):
354
343
return not self < other
@@ -388,7 +377,7 @@ def values(self):
388
377
389
378
def __lt__ (self , other ):
390
379
"""MaxValuePartitions are always greater than every other partition."""
391
- if isinstance (other , list ) or isinstance ( other , Position ):
380
+ if isinstance (other , ( Position , list ) ):
392
381
if self ._count != len (other ):
393
382
raise UnexpectedPartitionException (
394
383
f"Expected { self ._count } columns but list has { len (other )} ."
@@ -506,11 +495,9 @@ def set_as_max_value(self):
506
495
def as_partition (self ):
507
496
"""Return a concrete Partition that can be rendered into a SQL ALTER."""
508
497
if not self ._timestamp :
509
- raise ValueError ()
498
+ raise ValueError
510
499
if self ._position :
511
- return PositionPartition (f"p_{ self ._timestamp :%Y%m%d} " ).set_position (
512
- self ._position
513
- )
500
+ return PositionPartition (f"p_{ self ._timestamp :%Y%m%d} " ).set_position (self ._position )
514
501
return MaxValuePartition (f"p_{ self ._timestamp :%Y%m%d} " , count = self ._num_columns )
515
502
516
503
def __repr__ (self ):
@@ -535,7 +522,7 @@ class ChangePlannedPartition(_PlannedPartition):
535
522
536
523
def __init__ (self , old_part ):
537
524
if not is_partition_type (old_part ):
538
- raise ValueError ()
525
+ raise ValueError
539
526
super ().__init__ ()
540
527
self ._old = old_part
541
528
self ._num_columns = self ._old .num_columns
0 commit comments