Imports block detection needs to be smarter

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

@DamnWidget がすでに取り組んでいます。

2014年11月16日 から。

評価

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

調査の方向性

まず、報告にある Python の例で問題を再現し、importer の import ブロック検出とスコープ解析を調査します。try/except のフォールバック import が分割されたり ujsonas json として書き換えられたりせず、未解決シンボルと未参照シンボルの検出が引き続き正しいことを確認できれば完了です。

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

説明

bug

The current imports block detection need to be improved, for example, this is a typical and common import block in applications that supports several versions of some library or different versions of python even:

try:
    import ujson as json
except ImportError:
    import json

from collections import defaultdict
import sys

def main():
    print(os.uname())
    a = defaultdict(list)

This is translated to

import json
import sys
from collections import defaultdict

import ujsonas json


try:
    import ujson as json
except ImportError:
    import json

from collections import defaultdict
import sys

def main():
    print(os.uname())
    a = defaultdict(list)

That is a complete disaster, in the other hand, the scope is fine:

print(scope.find_unresolved_and_unreferenced_symbols())
(set(['os.uname']), set(['sys', 'json', 'main']))

The importer has no clue about what is really imported in the file as its not able to know where the imports block really ends.

主要言語
Python
スター
122
フォーク
21
PR マージ指標
30日以内にマージされた PR はありません

環境構築

このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。

はじめの一歩

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

alecthomas/importmagic のほかの issue

alecthomas/importmagic の issue をすべて見る

似ている issue

Python の issue をもっと見る

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

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