python / python/mypy

enigmatic "name already defined" error

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

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

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

説明

Please provide more information to help us understand the issue:

  • Are you reporting a bug, or opening a feature request?

Bug.

  • 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.

There are four pieces of code:

def func(x: int) -> int:
    return x + 1

def func(x):
    return x
def func(x):
    return x

def func(x: int) -> int:
    return x + 1
from test import func

def func(x: int) -> int:
    return x + 1
def func(x: int) -> int:
    return x + 1

from test import func

Whenever test is used as a module, test.py contains

def func(x):
    return x
  • What is the actual behavior/output?

The first three examples emits "Name 'func' already defined" error, but not the last

  • What is the behavior/output you expect?

All four should emit this error.

  • What are the versions of mypy and Python you are using?

mypy 0.720+dev.dc6da54f50d5443fe46308046719043eba03c84d (master at the time of bug report)
Python 3.7.3

  • What are the mypy flags you are using? (For example --strict-optional)

None.

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

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

はじめの一歩

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

調査の方向性

まず、報告された mypy のバージョンで 4 つのインライン再現を実行し、インポートされる関数には test.py を使用します。各インポート順序と再定義順序について診断結果を比較します。4 つすべてのケースで duplicate-definition エラーが出力されるというレポートの期待どおりの動作になれば完了です。

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

評価

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

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

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