Instagram / Instagram/LibCST

Warnings persist in Context

Open
#1,183 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
1.9k
Forks
229
PR merge metrics
No merged PRs in 30d

Description

I've been playing around with using libcst to copy (newly added) annotations from base class stubs to subclasses in a large legacy codebase. It's pretty neat!

There are some edge cases in this that I can't handle, and so kick them up to the user with `Codemod.warn()`. There is, however a minor UX issue when processing multiple files in one invocation: once I `warn()`, the warning persists in the `Context` for all subsequent files processed by that instance of the `Codemod`, and so I see spurious warnings attached to the wrong filename:
```console
> python3 -m libcst.tool codemod --hide-blacklisted-warnings -x icetray_codemod.ApplyStubsToSubclasses --stubs ../codemod/stubs.pkl --exclude-patterns 'icecube\.gulliver' sim-services
Calculating full-repo metadata...
Executing codemod...
1.82s 6% complete, 27.87s estimated for 46 files to go...Found 1 error (1 fixed, 0 remaining).
Codemodding /Users/jakob/Documents/IceCube/metaprojects/icetray/src/sim-services/python/gcd_validation/gcd_sanity_checker.py
WARNING: Mismatched arguments. icecube.icetray.I3Module.Finish has 1/0/0 pos-only/normal/kw-only params, I3GCDSanityChecker.Finish has 0/2/0
Successfully codemodded /Users/jakob/Documents/IceCube/metaprojects/icetray/src/sim-services/python/gcd_validation/gcd_sanity_checker.py with warnings

Codemodding /Users/jakob/Documents/IceCube/metaprojects/icetray/src/sim-services/python/gcd_validation/hit_generator.py
WARNING: Mismatched arguments. icecube.icetray.I3Module.Finish has 1/0/0 pos-only/normal/kw-only params, I3GCDSanityChecker.Finish has 0/2/0
Successfully codemodded /Users/jakob/Documents/IceCube/metaprojects/icetray/src/sim-services/python/gcd_validation/hit_generator.py with warnings

Codemodding /Users/jakob/Documents/IceCube/metaprojects/icetray/src/sim-services/python/gcd_validation/pe_generator.py
WARNING: Mismatched arguments. icecube.icetray.I3Module.Finish has 1/0/0 pos-only/normal/kw-only params, I3GCDSanityChecker.Finish has 0/2/0
Successfully codemodded /Users/jakob/Documents/IceCube/metaprojects/icetray/src/sim-services/python/gcd_validation/pe_generator.py with warnings

Codemodding /Users/jakob/Documents/IceCube/metaprojects/icetray/src/sim-services/python/label_events/__init__.py
WARNING: Mismatched arguments. icecube.icetray.I3Module.Finish has 1/0/0 pos-only/normal/kw-only params, I3GCDSanityChecker.Finish has 0/2/0
Successfully codemodded /Users/jakob/Documents/IceCube/metaprojects/icetray/src/sim-services/python/label_events/__init__.py with warnings

Finished codemodding 49 files!
- Transformed 31 files successfully.
- Skipped 18 files.
- Failed to codemod 0 files.
- 4 warnings were generated.
```
Is this the expected behavior?

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.