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

Abierto
#743 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 7 días

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
3/5
Tiempo estimado
1-2 días
Aptitud para principiantes
45/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Estancado
Stack tecnológico
python
Área
devtools

Línea de trabajo

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.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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.
Lenguaje dominante
Python
Estrellas
2.2k
Forks
197
Merge medio
2 d 13 h
PR fusionados (30 d)
5

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de python-rope/rope

Todos los issues de python-rope/rope

Issues similares

Más issues de Python

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.