Add option to select scope for doctests

Aperta
#161 14 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
45/100
Tipo di issue
Funzionalità
Chiarezza
Abbastanza chiara
Stato di attività
Ferma
Stack tecnologico
python

Direzione di ricerca

Start with the test.py reproducer in the issue and run pyflakes against it, then inspect how doctest code is analyzed. Add a selectable scope for doctests so imports in doctest scope do not produce false redefinition warnings, while genuine unused-import warnings remain; verify the reported output and the SymPy example.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Original report by asmeurer (@asmeurer?) on Launchpad:


test.py:

import sys

import sys

def func():
    """
    A docstring
    >>> import sys
    >>> sys.path
    """

    return 1

The pyflakes output is

test.py:1: 'sys' imported but unused
test.py:6: redefinition of unused 'sys' from line 1

The line 6 "redefinition of unused 'sys' from line 1" is incorrect, because the doctest scope is separate from the module scope.

I can't figure out how to reproduce it with a small file, but in this file: https://github.com/sympy/sympy/blob/master/sympy/physics/mechanics/functions.py, the output is

sympy/physics/mechanics/functions.py:160: redefinition of unused 'diff' from line 27
sympy/physics/mechanics/functions.py:200: redefinition of unused 'dynamicsymbols' from line 19
sympy/physics/mechanics/functions.py:261: redefinition of unused 'dynamicsymbols' from line 19
sympy/physics/mechanics/functions.py:458: redefinition of unused 'Point' from line 26
sympy/physics/mechanics/functions.py:508: redefinition of unused 'Point' from line 26

That is, it complains about the imports in the doctests, but not the imports themselves (because they actually are used in the file).

Lingua principale
Python
Stelle
1.5k
Fork
205
Merge medio
1g 2h
PR unite (30g)
5

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di PyCQA/pyflakes

Tutte le issue di PyCQA/pyflakes

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.