Closed
Description
I notice that a lot of current and future code in the mypy repository is not strictly related to mypy's core goal of being a static type-checker. You can detect these by the fact that they have few, if any, imports from the rest of mypy.
It would be cleaner if these were segregated to a separate package, especially for unit-testing purposes.
Current examples of nodes that are, or are leaning, this way:
codec
: Already a subpackage, which is documented to be used in a certain way, but it should be simple to keep it minimally compatible even if we figure out how to autoregister encodings.errors
: I am planning a full rewrite (in a newmypy.syntax
package) to add column and caret support, and possibly also other output formats for machine consumption. Some of this logic is obviously mypy-specific; other parts would be useful to others.messages
: It's not clear to me why this exists at all right now, but if it continues to exist, it ought to be a simple wrapper aroundgettext
. Clearer vision is required to see whether or not it will have any value on its own. See also Remove obsolete messages from mypy.messages #242myunit
: I am currently doing related cleanup as part of Fix/Improve Test Driver #721 (I need a separate module to run it as__main__
since it is also imported-from), but it would be nice if mypy tests could be run entirely by a standard test framework (I find pytest more convenient in that you don't have to arbitrarily add classes and can do proper fixtures instead of plain setup/teardown). This would make it easier to, say, collect coverage, run subsets of tests, and run tests in parallel (the current parallelization in Fix/Improve Test Driver #721 is a hack and very coarse)stubgen
: Ought to be a subpackage at least, and separate out the__main__
logic from the look-at-python logic.util
: Although not mypy-specific, does not stand on its own. Leave it here, every project has a garbage module.
And stuff I have created or am working on:
waiter
: a module I just added as a hack to make testing less intolerable. Only truly effective on Linux with Python 3.3 or later. Might be acting funny (but correct) on Travis, but I'm not sure. The details might change significantly if we stop running on the legacy infrastructure.myargs
: an idea I have to make implement argument parsing in a typesafe and readable manner, by introspecting the function/constructor annotations (withtyping.get_type_hints
- should it defer to__init__
automatically if passed a class and__call__
if passed any other Callable?).
Possible approaches for what to do with general-purpose modules:
- Do nothing and keep a big jumbled mess.
- Move them to a single
mypylibs
package, e.g.mypylibs.myunit
. (Name subject to bikeshedding; still will be the same pip package though). - Move them to under a
mypy.libs
subpackage, e.g.mypy.libs.myunit
. (Name subject to bikeshedding). - Make them all subpackages of
mypy
, even if they would only have an__init__.py
. - Move them to top level, e.g.
myunit
. - Move big ones to top level and keep the small ones under
mypy
. - Move big ones to top level and keep the small ones under
mypylibs
. - Move big ones to top level and keep the small ones under
mypy.libs
.
My preference is 2
, but keep open the possibility of 7
. Any such top-level packages should keep the my*
pattern.