python / python/mypy

stubgen infers function returns None if it passes or raise NotImplementedError

オープン
#9,104 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

topic-stubgen
主要言語
Python
スター
20.6k
フォーク
3.3k
PR マージ指標
PR 指標を取得中

説明

  • Are you reporting a bug, or opening a feature request?
    Reporting a bug, although I'm not sure what the intended behavior is.

  • Please insert below the code you are checking with mypy,
    or a mock-up repro if the source is private. We would appreciate
    if you try to simplify your case to a minimal repro.

class A:
    def f(self):
        raise NotImplementedError

    def g(self):
        """A is not an abstract base class"""
        return "Hello World"

class B(A):
    def f(self):
        return 5

class C:
    def f(self):
        pass
  • What is the actual behavior/output?
    stubgen output:
class A:
    def f(self) -> None: ...
    def g(self): ...

class B(A):
    def f(self): ...

class C:
    def f(self) -> None: ...
  • What is the behavior/output you expect?
class A:
    def f(self): ...
    def g(self): ...

class B(A):
    def f(self): ...

class C:
    def f(self): ...

This is because I would like to write code like

def h(a: A):
    return a.f()

h(B())

without typing errors. In realistic use cases, A has multiple subclasses.

  • What are the versions of mypy and Python you are using?
    Python 3.7.7
    mypy 0.782
    Do you see the same issue after installing mypy from Git master?
    Yes

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

Issue に示されている stubgen の動作から始め、A、B、C の例を使って再現します。NotImplementedError をそのまま渡す、または発生させるメソッドについて、stubgen が戻り値アノテーションをどのように推論するかを追跡し、その後、生成されたスタブがこれらの場合に None を追加しなくなっていることを確認しつつ、示されているサブクラスのメソッドを維持します。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
python
領域
tooling
issue の種類
バグ
難易度
3/5
見積もり時間
1〜2日
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
48/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。