Yesterday I started work on the *wax-off* script. This script strips 
annotations from function/method signatures. I want this script because I 
don't want to clutter Leo's sources.

The original idea was to write a second *wax-on* script that would restore 
the signatures, but Aha! There is another way: let the wax-off script write 
the original signature to the log, in stub file format. That is, each 
signature will end with "...". I can then copy the log to a stub (.pyi) 
file in leo/mypy_stubs.

I avoided stub files while working on annotations for several reasons:

- It was easiest to add the annotations directly to the sources.

- I was (and still am) unsure about how annotations in the stub file work 
with annotation in the actual source file. Does mypy merge them, or does 
one source take precedence?

The question *might* go away if the source file contains *no* annotations.  
I'll do some overdue experiments today to find out.

Yes, keeping stub files up to date will be a recurring issue, but that will 
become a problem only when using mypy, which is likely to happen rarely :-) 
More importantly, devs can use mypy's *--disallow-untyped-defs* option to 
ensure that stub files cover all new methods. 

*Summary*

Stub files (.pyi files in leo/mypy_stubs) should allow Leo to get the 
benefits of type annotations without cluttering the code.

mypy can warn if stub files are not up to date with their corresponding 
files.

Oh joy. There is no need for a wax-on script. This is a big deal because 
there is no need to tell wax-on what the annotations should be!

The wax-off script will be part of Leo 6.4, but it may be a few days before 
I complete it.

Edward

P. S. This regex finds all defs in a file:

def_pat = re.compile(
    r'def\s+([\w_]+)\s*\((.*?)\)(.*?):',
    re.MULTILINE + re.DOTALL)

wax-off can use this to write stubs.

The sub-pattern \((.*?)\) correctly finds the argument list, but regexes do 
not suffice to parse individual arguments. For that, wax-off will need a 
simple text scanner.

EKR

-- 
You received this message because you are subscribed to the Google Groups 
"leo-editor" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/leo-editor/e5db8cc3-f7ae-466f-b4cf-8bad01547f94n%40googlegroups.com.

Reply via email to