@@ -18,9 +18,8 @@ def timedelta_from_dict(r):
1818 for k , v in r .items ():
1919 if k == "days" :
2020 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
2423
2524
2625class Table :
@@ -96,32 +95,22 @@ def __new__(cls, *args):
9695 raise argparse .ArgumentTypeError (f"{ args } is not a single argument" )
9796 query_string = args [0 ].strip ()
9897 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 ';'" )
10299 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" )
106101
107102 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 '?'" )
111104 if query_string .count ("?" ) > 1 :
112105 raise argparse .ArgumentTypeError (
113106 f"[{ query_string } ] has more than one substitution variable '?'"
114107 )
115108
116109 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" )
120111 for term in SqlQuery .forbidden_terms :
121112 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 } ]" )
125114
126115 return super ().__new__ (cls , query_string )
127116
@@ -142,7 +131,7 @@ def to_sql_url(urlstring):
142131 urltuple = urlparse (urlstring )
143132 if urltuple .scheme .lower () != "sql" :
144133 raise argparse .ArgumentTypeError (f"{ urlstring } is not a valid sql://" )
145- if urltuple .path == "/" or urltuple . path == "" :
134+ if urltuple .path in { "/" , "" } :
146135 raise argparse .ArgumentTypeError (f"{ urlstring } should include a db path" )
147136 return urltuple
148137 except ValueError as ve :
@@ -259,7 +248,7 @@ def set_position(self, position_in):
259248 """Set the list of identifiers for this position."""
260249 if isinstance (position_in , Position ):
261250 self ._position = position_in .as_list ()
262- elif isinstance (position_in , list ) or isinstance ( position_in , tuple ):
251+ elif isinstance (position_in , ( list , tuple ) ):
263252 self ._position = [int (p ) for p in position_in ]
264253 else :
265254 raise ValueError (f"Unexpected position input: { position_in } " )
@@ -345,10 +334,10 @@ def __lt__(self, other):
345334
346335 # If ALL of v_mine >= v_other, then self is greater than other
347336 # 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+ )
352341
353342 def __ge__ (self , other ):
354343 return not self < other
@@ -388,7 +377,7 @@ def values(self):
388377
389378 def __lt__ (self , other ):
390379 """MaxValuePartitions are always greater than every other partition."""
391- if isinstance (other , list ) or isinstance ( other , Position ):
380+ if isinstance (other , ( Position , list ) ):
392381 if self ._count != len (other ):
393382 raise UnexpectedPartitionException (
394383 f"Expected { self ._count } columns but list has { len (other )} ."
@@ -506,11 +495,9 @@ def set_as_max_value(self):
506495 def as_partition (self ):
507496 """Return a concrete Partition that can be rendered into a SQL ALTER."""
508497 if not self ._timestamp :
509- raise ValueError ()
498+ raise ValueError
510499 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 )
514501 return MaxValuePartition (f"p_{ self ._timestamp :%Y%m%d} " , count = self ._num_columns )
515502
516503 def __repr__ (self ):
@@ -535,7 +522,7 @@ class ChangePlannedPartition(_PlannedPartition):
535522
536523 def __init__ (self , old_part ):
537524 if not is_partition_type (old_part ):
538- raise ValueError ()
525+ raise ValueError
539526 super ().__init__ ()
540527 self ._old = old_part
541528 self ._num_columns = self ._old .num_columns
0 commit comments