from typecheck import Interface, __declare__ # should do better interfaces for these Match = Interface("Match", "Regular expression match", lambda obj: hasattr(obj, "group")) Regex = Interface("Regex", "Regular expression object", lambda obj: hasattr(obj, "match")) __declare__(""" def compile(pattern: String, flags: Int) -> compiled_re: Regex def match(pattern: String, string: String, flags: Int) -> match : (Match | None) def search(pattern: String, string: String, flags: Int) -> match : (Match | None) def split(pattern: String, string: String, maxsplit: Int) -> value: Sequence((String | None)) def findall(pattern: String, string: String) -> value: Sequence def sub(pattern: String, repl: (String|Callable), string: String, count: Int) -> rc: String def subn(pattern: String, repl: String, count: Int) -> (new_string: String, number_of_subs_made: Int) def escape(pattern: String) -> escaped_string: String """)