mirror of
https://github.com/hwchase17/langchain.git
synced 2025-09-23 03:19:38 +00:00
cli: Add ruff rule UP (pyupgrade) (#31843)
See https://docs.astral.sh/ruff/rules/#pyupgrade-up All auto-fixed Co-authored-by: Eugene Yurtsev <eyurtsev@gmail.com>
This commit is contained in:
committed by
GitHub
parent
cd7dce687a
commit
b8e9b4adfc
@@ -1,16 +1,16 @@
|
||||
import http.client
|
||||
import json
|
||||
from typing import Any, Dict, List, Optional, TypedDict
|
||||
from typing import Any, Optional, TypedDict
|
||||
|
||||
WRITE_KEY = "310apTK0HUFl4AOv"
|
||||
|
||||
|
||||
class EventDict(TypedDict):
|
||||
event: str
|
||||
properties: Optional[Dict[str, Any]]
|
||||
properties: Optional[dict[str, Any]]
|
||||
|
||||
|
||||
def create_events(events: List[EventDict]) -> Optional[Any]:
|
||||
def create_events(events: list[EventDict]) -> Optional[Any]:
|
||||
try:
|
||||
data = {
|
||||
"events": [
|
||||
|
@@ -1,8 +1,7 @@
|
||||
from pathlib import Path
|
||||
from typing import Dict
|
||||
|
||||
|
||||
def find_and_replace(source: str, replacements: Dict[str, str]) -> str:
|
||||
def find_and_replace(source: str, replacements: dict[str, str]) -> str:
|
||||
rtn = source
|
||||
|
||||
# replace keys in deterministic alphabetical order
|
||||
|
@@ -1,8 +1,9 @@
|
||||
import hashlib
|
||||
import re
|
||||
import shutil
|
||||
from collections.abc import Sequence
|
||||
from pathlib import Path
|
||||
from typing import Dict, List, Optional, Sequence, TypedDict
|
||||
from typing import Optional, TypedDict
|
||||
|
||||
from git import Repo
|
||||
|
||||
@@ -18,7 +19,7 @@ class DependencySource(TypedDict):
|
||||
ref: Optional[str]
|
||||
subdirectory: Optional[str]
|
||||
api_path: Optional[str]
|
||||
event_metadata: Dict
|
||||
event_metadata: dict
|
||||
|
||||
|
||||
# use poetry dependency string format
|
||||
@@ -104,7 +105,7 @@ def parse_dependency_string(
|
||||
)
|
||||
|
||||
|
||||
def _list_arg_to_length(arg: Optional[List[str]], num: int) -> Sequence[Optional[str]]:
|
||||
def _list_arg_to_length(arg: Optional[list[str]], num: int) -> Sequence[Optional[str]]:
|
||||
if not arg:
|
||||
return [None] * num
|
||||
elif len(arg) == 1:
|
||||
@@ -116,11 +117,11 @@ def _list_arg_to_length(arg: Optional[List[str]], num: int) -> Sequence[Optional
|
||||
|
||||
|
||||
def parse_dependencies(
|
||||
dependencies: Optional[List[str]],
|
||||
repo: List[str],
|
||||
branch: List[str],
|
||||
api_path: List[str],
|
||||
) -> List[DependencySource]:
|
||||
dependencies: Optional[list[str]],
|
||||
repo: list[str],
|
||||
branch: list[str],
|
||||
api_path: list[str],
|
||||
) -> list[DependencySource]:
|
||||
num_deps = max(
|
||||
len(dependencies) if dependencies is not None else 0, len(repo), len(branch)
|
||||
)
|
||||
@@ -150,7 +151,7 @@ def parse_dependencies(
|
||||
def _get_repo_path(gitstring: str, ref: Optional[str], repo_dir: Path) -> Path:
|
||||
# only based on git for now
|
||||
ref_str = ref if ref is not None else ""
|
||||
hashed = hashlib.sha256((f"{gitstring}:{ref_str}").encode("utf-8")).hexdigest()[:8]
|
||||
hashed = hashlib.sha256((f"{gitstring}:{ref_str}").encode()).hexdigest()[:8]
|
||||
|
||||
removed_protocol = gitstring.split("://")[-1]
|
||||
removed_basename = re.split(r"[/:]", removed_protocol, 1)[-1]
|
||||
|
@@ -1,5 +1,5 @@
|
||||
from pathlib import Path
|
||||
from typing import Any, Dict, Optional, Set, TypedDict
|
||||
from typing import Any, Optional, TypedDict
|
||||
|
||||
from tomlkit import load
|
||||
|
||||
@@ -7,7 +7,7 @@ from tomlkit import load
|
||||
def get_package_root(cwd: Optional[Path] = None) -> Path:
|
||||
# traverse path for routes to host (any directory holding a pyproject.toml file)
|
||||
package_root = Path.cwd() if cwd is None else cwd
|
||||
visited: Set[Path] = set()
|
||||
visited: set[Path] = set()
|
||||
while package_root not in visited:
|
||||
visited.add(package_root)
|
||||
|
||||
@@ -35,7 +35,7 @@ class LangServeExport(TypedDict):
|
||||
|
||||
def get_langserve_export(filepath: Path) -> LangServeExport:
|
||||
with open(filepath) as f:
|
||||
data: Dict[str, Any] = load(f)
|
||||
data: dict[str, Any] = load(f)
|
||||
try:
|
||||
module = data["tool"]["langserve"]["export_module"]
|
||||
attr = data["tool"]["langserve"]["export_attr"]
|
||||
|
@@ -1,5 +1,6 @@
|
||||
from collections.abc import Iterable
|
||||
from pathlib import Path
|
||||
from typing import Any, Dict, Iterable, Tuple
|
||||
from typing import Any
|
||||
|
||||
from tomlkit import dump, inline_table, load
|
||||
from tomlkit.items import InlineTable
|
||||
@@ -12,12 +13,12 @@ def _get_dep_inline_table(path: Path) -> InlineTable:
|
||||
|
||||
|
||||
def add_dependencies_to_pyproject_toml(
|
||||
pyproject_toml: Path, local_editable_dependencies: Iterable[Tuple[str, Path]]
|
||||
pyproject_toml: Path, local_editable_dependencies: Iterable[tuple[str, Path]]
|
||||
) -> None:
|
||||
"""Add dependencies to pyproject.toml."""
|
||||
with open(pyproject_toml, encoding="utf-8") as f:
|
||||
# tomlkit types aren't amazing - treat as Dict instead
|
||||
pyproject: Dict[str, Any] = load(f)
|
||||
pyproject: dict[str, Any] = load(f)
|
||||
pyproject["tool"]["poetry"]["dependencies"].update(
|
||||
{
|
||||
name: _get_dep_inline_table(loc.relative_to(pyproject_toml.parent))
|
||||
@@ -33,7 +34,7 @@ def remove_dependencies_from_pyproject_toml(
|
||||
) -> None:
|
||||
"""Remove dependencies from pyproject.toml."""
|
||||
with open(pyproject_toml, encoding="utf-8") as f:
|
||||
pyproject: Dict[str, Any] = load(f)
|
||||
pyproject: dict[str, Any] = load(f)
|
||||
# tomlkit types aren't amazing - treat as Dict instead
|
||||
dependencies = pyproject["tool"]["poetry"]["dependencies"]
|
||||
for name in local_editable_dependencies:
|
||||
|
Reference in New Issue
Block a user