Skip to content

Commit

Permalink
[Internal] run pyupgrade on src/python/pants/backend (#13215)
Browse files Browse the repository at this point in the history
Run pyupgrade on `src/python/pants/backend`.
  • Loading branch information
asherf authored Oct 12, 2021
1 parent 9e6cf4a commit d049dbf
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from __future__ import annotations

from textwrap import dedent
from typing import List

import pytest

Expand Down Expand Up @@ -70,8 +69,8 @@ def assert_files_generated(
rule_runner: RuleRunner,
address: Address,
*,
expected_files: List[str],
source_roots: List[str],
expected_files: list[str],
source_roots: list[str],
mypy: bool = False,
extra_args: list[str] | None = None,
) -> None:
Expand Down
32 changes: 15 additions & 17 deletions src/python/pants/backend/go/target_type_rules_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,36 +72,35 @@ def rule_runner() -> RuleRunner:

def test_go_package_dependency_inference(rule_runner: RuleRunner) -> None:
rule_runner.write_files(
(
{
"foo/BUILD": "go_mod()",
"foo/go.mod": dedent(
"""\
{
"foo/BUILD": "go_mod()",
"foo/go.mod": dedent(
"""\
module go.example.com/foo
go 1.17
require github.com/google/go-cmp v0.4.0
"""
),
"foo/go.sum": dedent(
"""\
),
"foo/go.sum": dedent(
"""\
github.com/google/go-cmp v0.4.0 h1:xsAVV57WRhGj6kEIi8ReJzQlHHqcBYCElAvkovg3B/4=
github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
"""
),
"foo/pkg/foo.go": dedent(
"""\
),
"foo/pkg/foo.go": dedent(
"""\
package pkg
import "github.com/google/go-cmp/cmp"
func grok(left, right string) bool {
return cmp.Equal(left, right)
}
"""
),
"foo/cmd/main.go": dedent(
"""\
),
"foo/cmd/main.go": dedent(
"""\
package main
import (
"fmt"
Expand All @@ -110,9 +109,8 @@ def test_go_package_dependency_inference(rule_runner: RuleRunner) -> None:
func main() {
fmt.Printf("%s\n", pkg.Grok())
}"""
),
}
)
),
}
)
tgt1 = rule_runner.get_target(Address("foo", generated_name="./cmd"))
inferred_deps1 = rule_runner.request(
Expand Down
2 changes: 1 addition & 1 deletion src/python/pants/backend/java/compile/javac_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ class C implements A {}
coarsened_target = expect_single_expanded_coarsened_target(
rule_runner, Address(spec_path="a", target_name="a")
)
assert sorted([t.address.spec for t in coarsened_target.members]) == ["a/A.java", "b/B.java"]
assert sorted(t.address.spec for t in coarsened_target.members) == ["a/A.java", "b/B.java"]
request = CompileJavaSourceRequest(component=coarsened_target)

compiled_classfiles = rule_runner.request(CompiledClassfiles, [request])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from __future__ import annotations

from collections import defaultdict
from typing import FrozenSet, Set

from pants.engine.addresses import Address

Expand All @@ -27,7 +26,7 @@ class ConflictingTypeOwnershipError(Exception):

def __init__(self):
self._type_map: dict[str, Address] = {}
self._package_map: dict[str, Set[Address]] = defaultdict(set)
self._package_map: dict[str, set[Address]] = defaultdict(set)

def add_top_level_type(self, package: str, type_: str, address: Address):
"""Declare a single Address as the provider of a top level type.
Expand All @@ -51,7 +50,7 @@ def add_package(self, package: str, address: Address):
"""Add an address as one of the providers of a package."""
self._package_map[package].add(address)

def addresses_for_symbol(self, symbol: str) -> FrozenSet[Address]:
def addresses_for_symbol(self, symbol: str) -> frozenset[Address]:
"""Returns the set of addresses that provide the passed symbol.
`symbol` should be a fully qualified Java type (FQT) (e.g. `foo.bar.Thing`),
Expand Down
18 changes: 9 additions & 9 deletions src/python/pants/backend/project_info/source_file_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import textwrap
from dataclasses import dataclass
from enum import Enum
from typing import Any, Dict, Set, Tuple, cast
from typing import Any, cast

from pants.base.exiter import PANTS_FAILED_EXIT_CODE, PANTS_SUCCEEDED_EXIT_CODE
from pants.engine.collection import Collection
Expand Down Expand Up @@ -77,12 +77,12 @@ class ContentPattern:

@dataclass(frozen=True)
class ValidationConfig:
path_patterns: Tuple[PathPattern, ...]
content_patterns: Tuple[ContentPattern, ...]
required_matches: FrozenDict[str, Tuple[str]] # path pattern name -> content pattern names.
path_patterns: tuple[PathPattern, ...]
content_patterns: tuple[ContentPattern, ...]
required_matches: FrozenDict[str, tuple[str]] # path pattern name -> content pattern names.

@classmethod
def from_dict(cls, d: Dict[str, Any]) -> ValidationConfig:
def from_dict(cls, d: dict[str, Any]) -> ValidationConfig:
return cls(
path_patterns=tuple(PathPattern(**kwargs) for kwargs in d["path_patterns"]),
content_patterns=tuple(ContentPattern(**kwargs) for kwargs in d["content_patterns"]),
Expand Down Expand Up @@ -142,8 +142,8 @@ class RegexMatchResult:
"""The result of running regex matches on a source file."""

path: str
matching: Tuple
nonmatching: Tuple
matching: tuple
nonmatching: tuple


class RegexMatchResults(Collection[RegexMatchResult]):
Expand Down Expand Up @@ -191,8 +191,8 @@ def __init__(self, config: ValidationConfig):
:param dict config: Regex matching config (see above).
"""
# Validate the pattern names mentioned in required_matches.
path_patterns_used: Set[str] = set()
content_patterns_used: Set[str] = set()
path_patterns_used: set[str] = set()
content_patterns_used: set[str] = set()
for k, v in config.required_matches.items():
path_patterns_used.add(k)
if not isinstance(v, (tuple, list)):
Expand Down
8 changes: 4 additions & 4 deletions src/python/pants/backend/python/macros/pipenv_requirements.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import json
from pathlib import Path
from typing import Iterable, Mapping, Optional
from typing import Iterable, Mapping

from packaging.utils import canonicalize_name as canonicalize_project_name
from pkg_resources import Requirement
Expand Down Expand Up @@ -41,9 +41,9 @@ def __call__(
requirements_relpath: str | None = None,
*,
source: str | None = None,
module_mapping: Optional[Mapping[str, Iterable[str]]] = None,
type_stubs_module_mapping: Optional[Mapping[str, Iterable[str]]] = None,
pipfile_target: Optional[str] = None,
module_mapping: Mapping[str, Iterable[str]] | None = None,
type_stubs_module_mapping: Mapping[str, Iterable[str]] | None = None,
pipfile_target: str | None = None,
) -> None:
"""
:param requirements_relpath: The relpath from this BUILD file to the requirements file.
Expand Down
4 changes: 2 additions & 2 deletions src/python/pants/backend/python/macros/poetry_requirements.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import os
from dataclasses import dataclass
from pathlib import Path, PurePath
from typing import Any, Iterable, Iterator, List, Mapping, Sequence, cast
from typing import Any, Iterable, Iterator, Mapping, Sequence, cast

import toml
from packaging.utils import canonicalize_name as canonicalize_project_name
Expand All @@ -24,7 +24,7 @@


class PyprojectAttr(TypedDict, total=False):
extras: List[str]
extras: list[str]
git: str
rev: str
branch: str
Expand Down

0 comments on commit d049dbf

Please sign in to comment.