microsoft / pylance-release

Documentation and issues for Pylance
Creative Commons Attribution 4.0 International
1.7k stars 768 forks source link

Bring along imports when copy and pasting code across files #5119

Open patrick91 opened 10 months ago

patrick91 commented 10 months ago

Example:

import datetime
import json

def get_current_datetime_info() -> str:
    now = datetime.datetime.now()

    data = {
        "date": now.strftime("%Y-%m-%d"),
        "time": now.strftime("%H:%M:%S"),
        "message": "Hello, world!"
    }

    return json.dumps(data, indent=4)

if I copy this snippet or any line code that uses one some of the imports it would be nice to get the imports where we paste those lines.

There's the same request for TS here: https://github.com/microsoft/TypeScript/issues/50187

debonte commented 10 months ago

Is this something that we could solve by implementing format on paste? https://github.com/microsoft/pylance-release/discussions/4342

patrick91 commented 10 months ago

Is this something that we could solve by implementing format on paste? #4342

by finding the required imports? or by remembering the imports? the first one might be trickier since there might be multiple module exporting the same "name"