Skip to content

Commit 5f2ab77

Browse files
committed
Revert "chore: Fix more type issues"
This reverts commit dede4a2.
1 parent dede4a2 commit 5f2ab77

File tree

1 file changed

+26
-26
lines changed

1 file changed

+26
-26
lines changed

normfn

+26-26
Original file line numberDiff line numberDiff line change
@@ -270,17 +270,15 @@ def main(argv, syserr_handler):
270270
logger.debug(f"Valid years are: {year_list}")
271271
YEAR = r"(" + "|".join(year_list) + r")"
272272

273-
filenames: list[str] = args.filenames # pyright: ignore[reportAny]
274-
275273
with suppress(QuitException):
276-
for filename in filenames:
274+
for filename in args.filenames:
277275
filename = os.path.abspath(filename)
278276
if not os.path.exists(filename):
279277
raise FatalException(
280278
filename + " specified on the command line does not exist."
281279
)
282280

283-
if os.path.isdir(filename) and args.recursive: # pyright: ignore[reportAny]
281+
if os.path.isdir(filename) and args.recursive:
284282
new_filename = process_filename(filename, args)
285283
assert new_filename is not None
286284
walk_tree(new_filename, args)
@@ -315,8 +313,8 @@ def walk_tree(dirname: str, args):
315313
def datetime_prefix(args, non_extension: str, filename: str):
316314
logger = logging.getLogger("normfn")
317315

318-
def first_not_none[T](lst: list[T]):
319-
for item in lst:
316+
def first_not_none(list: list):
317+
for item in list:
320318
if item is not None:
321319
return item
322320

@@ -479,7 +477,7 @@ def datetime_prefix(args, non_extension: str, filename: str):
479477
if number_of_subs == 0:
480478
logger.debug("Didn't find date or time")
481479

482-
timetouse = get_timetouse(args.time_option, filename)
480+
timetouse = get_timetouse(args, filename)
483481

484482
newname_with_dash_if_needed = (
485483
("-" + newname) if not args.discard_existing_name else ""
@@ -521,7 +519,7 @@ def process_filename(filename: str, args):
521519
logger.debug("New filename would be identical, skipping.")
522520
return original_filename
523521

524-
validate_move(args.force, original_filename, filename)
522+
validate_move(args, original_filename, filename)
525523

526524
move_it = True
527525

@@ -534,14 +532,14 @@ def process_filename(filename: str, args):
534532
new_filename = os.path.join(
535533
os.path.dirname(original_filename), new_filename
536534
)
537-
validate_move(args.force, original_filename, new_filename)
535+
validate_move(args, original_filename, new_filename)
538536
filename = new_filename
539537
else:
540538
move_it = True if move_it == b"y" else False
541539

542540
if move_it:
543541
if not args.dry_run:
544-
shiftfile(args.undo_log_file, original_filename, filename)
542+
shiftfile(args, original_filename, filename)
545543
return filename
546544
else:
547545
logger.info(
@@ -571,22 +569,22 @@ def should_exclude(filename: str, basename: str):
571569
return (match, exclude_pattern)
572570

573571

574-
def get_timetouse(time_option: str, filename: str):
572+
def get_timetouse(args, filename: str):
575573
ctime = datetime.fromtimestamp(os.path.getctime(filename))
576574
mtime = datetime.fromtimestamp(os.path.getmtime(filename))
577575

578-
if time_option == "now":
576+
if args.time_option == "now":
579577
timetouse = datetime.now()
580-
elif time_option == "earliest":
578+
elif args.time_option == "earliest":
581579
timetouse = min(ctime, mtime)
582580
else:
583581
timetouse = max(ctime, mtime)
584582

585583
return timetouse
586584

587585

588-
def validate_move(force: bool, original_filename: str, filename: str) -> None:
589-
if os.path.exists(filename) and not force:
586+
def validate_move(args, original_filename: str, filename: str) -> None:
587+
if os.path.exists(filename) and not args.force:
590588
raise FatalException(
591589
f"Want to move {original_filename.strip()} to "
592590
f"{filename}, but it already exists."
@@ -606,7 +604,7 @@ def rlinput(prompt: str, prefill: str = ""):
606604
readline.set_startup_hook()
607605

608606

609-
def shiftfile(undo_log_file: str, source: str, target: str):
607+
def shiftfile(args, source: str, target: str):
610608
logger = logging.getLogger("normfn")
611609

612610
source = os.path.abspath(source)
@@ -625,17 +623,17 @@ def shiftfile(undo_log_file: str, source: str, target: str):
625623
else:
626624
raise
627625

628-
if undo_log_file:
629-
check_undo_log_file_header(undo_log_file)
630-
with open(undo_log_file, "a", encoding="utf-8") as log_file:
626+
if args.undo_log_file:
627+
check_undo_log_file_header(args)
628+
with open(args.undo_log_file, "a", encoding="utf-8") as log_file:
631629
_ = log_file.write(f"# {dt_now}: moving {source} to {target}\n")
632630
_ = log_file.write(f"mv {shlex.quote(target)} {shlex.quote(source)}\n")
633631
logger.info(source + " moved to " + target)
634632

635633

636-
def check_undo_log_file_header(undo_log_file: str):
637-
if not os.path.exists(undo_log_file):
638-
with open(undo_log_file, "w") as log_file:
634+
def check_undo_log_file_header(args):
635+
if not os.path.exists(args.undo_log_file):
636+
with open(args.undo_log_file, "w") as log_file:
639637
wrapper = textwrap.TextWrapper(initial_indent="# ", subsequent_indent="# ")
640638
_ = log_file.write("#!/bin/sh\n")
641639
_ = log_file.write(
@@ -651,7 +649,9 @@ def check_undo_log_file_header(undo_log_file: str):
651649
wrapper.fill(
652650
"This file contains shell commands which can be run to invert (undo) the effects of "
653651
"running normfn. They must be run in *reverse order*. You can achieve "
654-
f"this by running `tac {undo_log_file} | sh`. If you wish, you can edit "
652+
"this by running `tac "
653+
+ args.undo_log_file
654+
+ " | sh`. If you wish, you can edit "
655655
"the file first to control which actions are undone."
656656
)
657657
+ "\n"
@@ -706,10 +706,10 @@ def insensitiveize(string: str) -> str:
706706
return "".join(map(lambda char: ("[" + char.lower() + char.upper() + "]"), string))
707707

708708

709-
class FatalException[T](Exception):
710-
def __init__(self, value: T):
709+
class FatalException(Exception):
710+
def __init__(self, value):
711711
Exception.__init__(self, value)
712-
self.value: T = value
712+
self.value = value
713713

714714
def __str__(self):
715715
return repr(self.value)

0 commit comments

Comments
 (0)