Skip to content

Commit

Permalink
Merge pull request #754 from python-rope/minor-refactorings
Browse files Browse the repository at this point in the history
Minor type hint improvements
  • Loading branch information
lieryan committed Mar 8, 2024
2 parents 8e61a68 + 7a3d4c8 commit 2df076d
Showing 1 changed file with 21 additions and 10 deletions.
31 changes: 21 additions & 10 deletions rope/contrib/autoimport/sqlite.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""AutoImport module for rope."""

from __future__ import annotations

import contextlib
import json
import re
Expand All @@ -14,7 +16,16 @@
from itertools import chain
from pathlib import Path
from threading import local
from typing import Generator, Iterable, Iterator, List, Optional, Set, Tuple
from typing import (
Generator,
Iterable,
Iterator,
List,
Optional,
Set,
Tuple,
TYPE_CHECKING,
)

from rope.base import exceptions, libutils, resourceobserver, taskhandle, versioning
from rope.base.project import Project
Expand All @@ -41,9 +52,13 @@
from rope.refactor import importutils


if TYPE_CHECKING:
from collections.abc import Collection


def get_future_names(
packages: List[Package], underlined: bool, job_set: taskhandle.BaseJobSet
) -> Generator[Future, None, None]:
) -> Generator[Future[Collection[Name]], None, None]:
"""Get all names as futures."""
with ProcessPoolExecutor() as executor:
for package in packages:
Expand Down Expand Up @@ -81,7 +96,6 @@ class AutoImport:
"""

connection: sqlite3.Connection
memory: bool
project: Project
project_package: Package
Expand Down Expand Up @@ -179,7 +193,7 @@ def calculate_project_hash(data: str) -> str:
return sqlite3.connect(project.ropefolder.pathlib / "autoimport.db")

@property
def connection(self):
def connection(self) -> sqlite3.Connection:
"""
Creates a new connection if called from a new thread.
Expand Down Expand Up @@ -593,9 +607,6 @@ def _removed(self, resource):
modname = self._resource_to_module(resource).modname
self._del_if_exist(modname)

def _add_future_names(self, names: Future):
self._add_names(names.result())

@staticmethod
def _convert_name(name: Name) -> tuple:
return (
Expand All @@ -606,12 +617,12 @@ def _convert_name(name: Name) -> tuple:
name.name_type.value,
)

def add_aliases(self, aliases: Iterable[Alias]):
def add_aliases(self, aliases: Collection[Alias]):
if aliases:
self._executemany(models.Alias.objects.insert_into(), aliases)

def _add_names(self, names: Iterable[Name]):
if names is not None:
def _add_names(self, names: Collection[Name]):
if names:
self._executemany(
models.Name.objects.insert_into(),
[self._convert_name(name) for name in names],
Expand Down

0 comments on commit 2df076d

Please sign in to comment.