Package: typing-copilot
typing_copilotHelper for starting to type-hint large codebases withmypy. When installed, available as the commandtyping_copilot.Example output generated when generating amypy.inifile for theGraphQL compilerproject (PR link):# First, enter the project's virtual environment.# Make sure the project's dependencies are installed in the environment!$poetryshell# or "pipenv shell" or "source venv/bin/activate" or ...<...>

$typing_copilotinit
typing_copilotv0.4.0

Runningmypyoncewithlaxestsettingstoestablishabaseline.Pleasewait...

Collectingmypyerrorsfromstrictestcheckconfiguration.Pleasewait...

Strictruncompletedanduncovered2955mypyerrors.Buildingthestrictestmypyconfig
suchthatallconfiguredmypychecksstillpass...

>Mypywasunabletofindtypehintsforsome3rdpartymodules,configuringmypyto
ignorethem.Moreinfo:https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-importsAffectedmodules:['arrow','cached_property','funcy','neo4j','parameterized','pyorient','pytest','redisgraph','setuptools','snapshottest','sqlalchemy']>Constructed126mypyerrorsuppressionrulesacross65modules.

Configgenerated(306lines).Validatingthenewsetupbeforeupdatingyourmypy.ini
file.Pleasewait...

Validationcomplete.Yourmypy.inifilehasbeenupdated.Happytype-safecoding!MotivationStarting to usemypyin a large codebase can feel like a chicken-and-egg problem:You are unable to turn on meaningfulmypyenforcement since a large portion of the codebase is not compliant.It is difficult to get the codebase compliant withoutmypyenforcement: since proper typing is not enforced, even brand-new code is frequently not fully compliant, and it feels like you are making one step forward and two steps back.mypyallows specifying different levels of rule enforcement on a per-module basis. However, writing a good per-modulemypyconfiguration is an extremely time-consuming process:mypymust be executed (in a strict configuration) against that module, the resulting errors must be triaged, and an appropriate set of rules for the modules must be produced. Applying this process on a large codebase can easily take hours or days of work.typing_copilotaims to make this process extremely quick and simple. After installing this package in your project's development environment, runningtyping_copilot initwill autogenerate amypy.inifile with the strictest set ofmypyrules that your code currently passes. In future runs,mypywill automatically use the newmypy.inifile, thereby ensuring that no future code edits violate any typing rules that the current codebase satisfies.You can then also use themypy.inifile to see which checks had to be disabled for which of your project's modules, and use that information to guide your future typing efforts. You can also periodically re-runtyping_copilot tightento regenerate amypy.inifile, in case your project's typing state has improved and stricter rules may now be adopted.Ideally, consider usingtyping_copilotin a "ratcheting" fashion, where your project is always on the tightest possiblemypy.iniconfiguration. The easiest way to do so is to runtyping_copilot tighten --error-if-can-tightenin your CI environment, which willexit 1in case your currentmypy.iniis not the tightest possible one for your project.In the future, we hope to add additional functionality totyping_copilot:a command that highlights opportunities where a small amount of work can allow a new rule to be enabled for a new module, allowing you to maximize your project's typing enforcement;support for additionalmypyrules.UsageNavigate to the root directory of the project on which you'd like to usetyping_copilot.Enter the project's virtualenv, if using one, and ensure the project's own package and its dependencies are installed.Runtyping_copilot:pipinstalltyping_copilot

typing_copilotinitCurrently,typing_copilotis unable to supportmypy.inifiles that it did not generate. If you are already usingmypybut you'd like to transition to usingtyping_copilotto manage yourmypy.inifile, you can make use of the--overwriteflag:typing_copilotinit--overwriteAfter creating your initialmypy.inifile withtyping_copilot, you can also usetyping_copilotto attempt to tighten yourmypy.iniconfiguration. This is useful, for example, if you've recently added type hints to your code and believe that should enable a tighter newmypy.iniconfiguration. Simply run the following to update yourmypy.inito the tightest passingmypyconfiguration:typing_copilottightenIn a CI environment,typing_copilotcan simultaneously ensure both that your code passesmypychecks with the currentmypy.iniconfiguration, and that the currentmypy.inifile is the tightestmypyconfig that your code is able to support. Simply use the--error-if-can-tightenflag in thetightencommand:typing_copilottighten--error-if-can-tightenHowtyping_copilotworkstyping_copilot initWith this command,typing_copilotwill first runmypyusing a minimal set ofmypychecks which are always enabled and cannot be turned off. You'll need to fix any errorsmypyfinds using these checks before the command will be able to proceed.Once the minimalmypychecks pass,typing_copilot initwill automatically re-runmypywith the strictest supported set of checks, and collect the reported errors. After analyzing the errors, it will generate the strictest set of checks that will not cause errors, validate them by runningmypyagainst your project one more time, and then create a newmypy.inifile with this new "strictest valid" configuration. We generally refer to this "strictest valid" configuration as the project's "tightest" configuration, hence thetightencommand described below.typing_copilot tightenWith this command,typing_copilotwill first runmypyusing your currentmypy.inifile, ensuring that the current configuration does not produce anymypyerrors. Assuming no errors are found,typing_copilotwill then follow the same procedure as in theinitcommand to find the tightestmypyconfiguration your project's current state supports. Finally, it will compare this newly-found tightest configuration against your currentmypy.iniconfiguration, and either update yourmypy.inifile or return an error, depending on whether the--error-if-can-tightenis set.Reporting issuesThis is a project I built in my spare time, please be gentle :)GitHub issues are the preferred avenue for reporting issues withtyping_copilot. Please do not email me or any other contributors with questions or issue reports, unless you have our explicit consent to do so.To ensure the best odds that we can diagnose and fix any problems together, please make sure to include in your issue report the log produced using the--verboseoption, together with links to the source code being analyzed bymypyandtyping_copilot.As always, pull requests highly encouraged and gratefully accepted.