Skip to content

Add agent skills for migration to mypyc and mypyc optimizations - #22072

Merged
JukkaL merged 19 commits into
masterfrom
mypyc-agent-skills
Sep 30, 2026
Merged

JukkaL merged 19 commits into
masterfrom
mypyc-agent-skills

Conversation

@JukkaL

@JukkaL JukkaL commented Sep 30, 2026 •

Copy link
Copy Markdown
Collaborator

The idea is that these could be installed to a coding agent like Claude Code or Codex, and the agent can use the instructions to migrate/prepare code for mypyc compilation, and to optimize code for better performance under mypyc. I have two separate skills, since it often makes sense to first only do fairly minimal changes to get code to work correctly when compiled, and further optimizations can be a later step. Also, to be most effective, the optimization workflow needs some way to benchmark and profile changes, whereas the migration workflow can just check that code compiled and tests pass, so these are somewhat different use cases.

I used this with Claude Opus 5.5 to migrate a library at work to mypyc, and the results looked reasonable (though I haven't deployed the change the yet). This should be considered experimental still.

Comment on lines +61 to +66
Class-level constants should also be annotated:

```
class Foo:
MAX_ITEMS = 100
```

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and also instance attributes that are only assigned in the constructor.

Comment on lines +346 to +350
### Annotations Are Enforced at Runtime

Compiled code checks argument, return and attribute types at runtime,
and raises `TypeError` if a value has the wrong type. Code that worked
despite an inaccurate annotation may fail after compilation:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

might be worth mentioning here to remove assertions that become unreachable because of this, for example when validating attributes passed to a function. and if those assertions are tested then the test should be changed to expect TypeError.

Comment on lines +20 to +25
* Add `@final` class decorator to internal/helper classes that conform to
these rules, if the class clearly isn't intended to be subclassed:
* They don't have any subclasses in the codebase.
* They aren't an ABC or a protocol.
* They aren't an exception class.
* They don't subclass any stdlib class (other than `object`).

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if the class can't be made @final, annotate methods that are not overridden with @final.

Comment on lines +98 to +99
previously had none also causes mypy to type check its body; fix any new type
errors that this produces.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also consider using cast when a more specific type can be determined statically but cannot be used as a type annotation, for example because changing the interface of a function would cause a lot of typing issues in dependent code.

@JukkaL

JukkaL commented Sep 30, 2026

Copy link
Copy Markdown
Collaborator Author

I'll address the comments in a follow-up PR which will likely include some other tweaks.

@JukkaL
JukkaL merged commit baa9db5 into master Sep 30, 2026
2 checks passed
@JukkaL
JukkaL deleted the mypyc-agent-skills branch September 30, 2026 15:48
ilevkivskyi pushed a commit that referenced this pull request Oct 3, 2026
Fix `check-manifest` be explicitly excluding the `skills` dir.
Followup to #22072

Build failure:
https://github.com/mypyc/mypy_mypyc-wheels/actions/runs/37029975663/job/110914062986#step:5:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants