Applying the Inline Method refactoring does not add the required import.

Aperta
#743 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 7 giorni

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
45/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Ferma
Stack tecnologico
python
Ambito
devtools

Direzione di ricerca

Reproduce with the two files in the report: src/main.py defines Base.split with the default argument sys.maxsize, and src/test.py calls it, so inlining should copy that default into test.py. Start from rope's Inline Method refactoring and check how it collects imports for names used in the inlined body. Done when applying the refactoring to Base.split leaves import sys at the top of test.py, and a test covers the default-argument case.

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

Descrizione

bug inline-refactor

Steps to reproduce the behavior:

  1. Code before refactoring:

structure:
project
| - src
| -- __init__.py
| -- main.py
| -- test.py

main.py

import sys


class Base:
    def __init__(self, text):
        self.raw = text

    def split(self, sep=None, maxsplit=sys.maxsize):
        return self.raw.split(sep, maxsplit)[0]

test.py

from unittest import TestCase
from src.split_main import Base

class Test(TestCase):
    def test_split(self):
        blob = Base('Beautiful is better')
        self.assertEqual(blob.split(), ['Beautiful'])
  1. Apply the Inline Method to Base.split().

  2. Expected code after refactoring:

structure:
project
| - src
| -- __init__.py
| -- main.py
| -- test.py

main.py

class Base:
    def __init__(self, text):
        self.raw = text

test.py

import sys
from unittest import TestCase
from src.split_main import Base

class Test(TestCase):
    def test_split(self):
        blob = Base('Beautiful is better')
        self.assertEqual(blob.raw.split(None, sys.maxsize)[0], ['Beautiful'])
  1. The "import sys" is not automatically added.
Lingua principale
Python
Stelle
2.2k
Fork
197
Merge medio
2g 13h
PR unite (30g)
5

Preparare l'ambiente

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 python-rope/rope

Tutte le issue di python-rope/rope

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.