python / python/mypy

Optionally flag known mypyc compatibility issues in mypy

Open
#14,715 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

feature topic-mypyc
Dominant language
Python
Stars
20.6k
Forks
3.3k
PR merge metrics
PR metrics pending

Description

Feature

Mypyc is incompatible in some ways with CPython semantics (mypyc/mypyc#973 is a recent example). Add an optional error code to mypy that detects some of these incompatible features in code even when not using mypyc. We can also explain how to work around the issues in notes, or include links to documentation.

Here are some issues we could flag:

  • Overriding methods in subclasses of built-in types such as int or str that mypyc can't use.
  • Subclassing compiled classes that don't support interpreted subclasses. This would require knowledge of which modules will be compiled.
  • Monkey patching native functions or methods. This is usually flagged already by mypy, but we could perhaps detect this in additional cases, add a note about mypyc when relevant, and use a separate error code.

Pitch

Code that isn't compiled with mypyc can trigger incompatible behavior or exceptions when interacting with mypyc-compiled modules, and this is confusing. These messages would make it easier to avoid using things that may cause issues with mypyc, if part of a project is compiled with mypyc.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reviewing the mypyc#973 example and mypy's existing diagnostics for monkey patching. Define the scope of an optional error code for built-in subclass overrides, compiled-class subclassing, and relevant monkey patching, including any notes or documentation links. Done means the selected incompatibilities are detected without requiring mypyc and the behavior is covered by tests.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
compilers
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.