if isinstance(prm.annotation, type): # Basic types
return get_argspecs(prm.annotation())
elif hasattr(prm.annotation, '__args__'): # Unions
+ # BUG: Unions, but also lists and other containers!
+ # Really, we want lists to be treated separately.
# ASSUME: Order of types in signatures indicate order of preference.
for type_ in prm.annotation.__args__:
try:
--- /dev/null
+from abc import abstractmethod
+from pathlib import Path
+import sys
+from typing import Optional, Protocol
+
+
+class IO(Protocol):
+
+ @abstractmethod
+ def read():
+ pass
+
+ @abstractmethod
+ def write():
+ pass
+
+
+class Stdio(IO):
+
+ @staticmethod
+ def read(file: Optional[Path])->str:
+ if file is None:
+ contents = sys.stdin.read()
+ else:
+ with open(file, "r") as f:
+ contents = f.read()
+ return contents
+
+ @staticmethod
+ def write(contents, outfile: Optional[Path]=None):
+ if outfile is not None:
+ with open(outfile, "w") as out:
+ out.write(contents)
+ else:
+ sys.stdout.write(contents)
\ No newline at end of file