Hi, I like this overlay idea and I think I have a good use case for it. It is not possible to represent all the things that Django can do in the type system at present. Therefore, to support type-checking those things, people have developed a mypy plug-in which handles them. But that is of course limited to mypy, which limits its utility. An example of what it does is adding an extra attribute to a class with a name derived from another attribute whenever it is of a certain type. I’ve been prototyping a tool (not published yet) that can automatically generate these extra annotations (and sometimes modifications to existing annotations). It currently uses libcst’s codemod facility to modify the .py files in place, but it would be much better if it could just generate overlays alongside the existing files. This would avoid cluttering the original source files. It would also be cool to allow for optional comments in the overlay file which would indicate which line in the original source file the generated code line came from (kind of like a source map in TypeScript) so that any error messages would point to the original source file. I then imagine a watcher which looks for changes in the .py files and generates new overlay files whenever they are changed. I would be super excited to see overlay files become a reality, to support these kinds of situations. Best regards, Seth Yastrov
On 15 Sep 2022, at 15.21, Irv Lustig <irv@princeton.com> wrote:
I like the overlay idea. Is it worth it to put together a PEP proposal for this?
-Irv
On Wed, Sep 14, 2022 at 6:49 PM Martin DeMello <mdemello@google.com> wrote: The pytype team has internally discussed the idea of supporting "stub overlays". Our idea was to do this at a module level, so that definitions would be recursively merged without any explicit annotations; in this instance you would have a file named `pandas_overlay.pyi` and define `class DataFrame` in it, which would modify `pandas.DataFrame` when imported.
martin
Typing-sig mailing list -- typing-sig@python.org To unsubscribe send an email to typing-sig-leave@python.org https://mail.python.org/mailman3/lists/typing-sig.python.org/ Member address: syastrov@gmail.com