Skip to content

Commit

Permalink
Bump default MyPy version to 0.800 (pantsbuild#11506)
Browse files Browse the repository at this point in the history
  • Loading branch information
Eric-Arellano authored Jan 31, 2021
1 parent 6484d56 commit 228d763
Show file tree
Hide file tree
Showing 12 changed files with 30 additions and 24 deletions.
8 changes: 4 additions & 4 deletions 3rdparty/python/constraints.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Generated by build-support/bin/generate_lockfile.sh on Fri Jan 22 05:13:08 PM PST 2021
# Generated by build-support/bin/generate_lockfile.sh on Sat Jan 30 06:19:07 MST 2021
ansicolors==1.1.8
attrs==20.3.0
beautifulsoup4==4.6.3
Expand All @@ -11,7 +11,7 @@ freezegun==1.0.0
idna==2.10
iniconfig==1.1.1
monotonic==1.5
mypy==0.782
mypy==0.800
mypy-extensions==0.4.3
packaging==20.8
pex==2.1.28
Expand All @@ -23,7 +23,7 @@ pycparser==2.20
pyOpenSSL==20.0.1
pyparsing==2.4.7
pystache==0.5.4
pytest==6.2.1
pytest==6.2.2
python-dateutil==2.8.1
PyYAML==5.4.1
requests==2.25.1
Expand All @@ -33,4 +33,4 @@ six==1.15.0
toml==0.10.2
typed-ast==1.4.2
typing-extensions==3.7.4.2
urllib3==1.26.2
urllib3==1.26.3
2 changes: 1 addition & 1 deletion 3rdparty/python/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ freezegun==1.0.0
# .value_history.ranked_values[-1].value
# '
#
mypy==0.782
mypy==0.800

packaging==20.8
pathspec==0.8.0
Expand Down
2 changes: 1 addition & 1 deletion build-support/bin/generate_docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ def process_targets_input(cls, help_info: Dict) -> Dict[str, Dict[str, Any]]:
field["default_or_required"] = (
"required" if field["required"] else f"default: <code>{default_str}</code>"
)
target["fields"] = sorted(target["fields"], key=lambda fld: fld["alias"])
target["fields"] = sorted(target["fields"], key=lambda fld: cast(str, fld["alias"]))

return cast(Dict[str, Dict[str, Any]], target_info)

Expand Down
14 changes: 9 additions & 5 deletions build-support/bin/generate_travis_yml.py
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,9 @@ def linux_shard(
}
if load_test_config:
setup["before_script"] = [AWS_GET_PANTS_PEX_COMMAND]
setup["env"].append(f"BOOTSTRAPPED_PEX_KEY_SUFFIX=py{python_version.number}.linux")
setup["env"].append( # type: ignore[attr-defined]
f"BOOTSTRAPPED_PEX_KEY_SUFFIX=py{python_version.number}.linux"
)
setup = {**setup, **CACHE_PANTS_RUN}
if use_docker:
setup["services"] = ["docker"]
Expand Down Expand Up @@ -414,8 +416,10 @@ def osx_shard(
if osx_image is not None:
setup["osx_image"] = osx_image
if load_test_config:
setup["before_script"].append(AWS_GET_PANTS_PEX_COMMAND)
setup["env"].append(f"BOOTSTRAPPED_PEX_KEY_SUFFIX=py{python_version.number}.osx")
setup["before_script"].append(AWS_GET_PANTS_PEX_COMMAND) # type: ignore[attr-defined]
setup["env"].append( # type: ignore[attr-defined]
f"BOOTSTRAPPED_PEX_KEY_SUFFIX=py{python_version.number}.osx"
)
return setup


Expand Down Expand Up @@ -449,7 +453,7 @@ def _bootstrap_env(*, python_version: PythonVersion, platform: Platform) -> List

def bootstrap_linux(python_version: PythonVersion) -> Dict:
shard = {
**CACHE_NATIVE_ENGINE,
**CACHE_NATIVE_ENGINE, # type: ignore[arg-type]
**linux_shard(load_test_config=False, python_version=python_version, use_docker=True),
"name": f"Build Linux native engine and pants.pex (Python {python_version.decimal})",
"stage": python_version.default_stage(is_bootstrap=True).value,
Expand All @@ -470,7 +474,7 @@ def bootstrap_linux(python_version: PythonVersion) -> Dict:

def bootstrap_osx(python_version: PythonVersion) -> Dict:
shard = {
**CACHE_NATIVE_ENGINE,
**CACHE_NATIVE_ENGINE, # type: ignore[arg-type]
# We request the oldest image we can (corresponding to OSX 10.11) for maximum compatibility.
# We use 10.11 as a minimum to avoid https://github.com/rust-lang/regex/issues/489.
# See: https://docs.travis-ci.com/user/reference/osx/#OS-X-Version
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from pants.backend.python.target_types import InterpreterConstraintsField
from pants.backend.python.util_rules.pex import PexInterpreterConstraints
from pants.base.specs import AddressSpecs, DescendantAddresses
from pants.engine.addresses import Addresses
from pants.engine.addresses import Address, Addresses
from pants.engine.console import Console
from pants.engine.goal import Goal, GoalSubsystem, Outputting
from pants.engine.rules import Get, MultiGet, collect_rules, goal_rule
Expand Down Expand Up @@ -87,7 +87,7 @@ async def py_constraints(
for t in (*all_expanded_targets, *all_explicit_targets)
if t.has_field(InterpreterConstraintsField)
},
key=lambda tgt: tgt.address,
key=lambda tgt: cast(Address, tgt.address),
)

constraints_per_tgt = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,7 @@ def add(x: int, y: int) -> int:

result = run_mypy(rule_runner, [py2_target, py3_target])
assert len(result) == 2
py2_result, py3_result = sorted(result, key=lambda res: res.partition_description)
py2_result, py3_result = sorted(result, key=lambda res: res.partition_description or "")

assert py2_result.exit_code == 0
assert py2_result.partition_description == "['CPython==2.7.*', 'CPython==2.7.*,>=3.6']"
Expand Down Expand Up @@ -600,7 +600,7 @@ def test_source_plugin(rule_runner: RuleRunner) -> None:
"""\
python_requirement_library(
name='mypy',
requirements=['mypy==0.782'],
requirements=['mypy==0.800'],
)
python_requirement_library(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class MyPy(PythonToolBase):
options_scope = "mypy"
help = "The MyPy Python type checker (http://mypy-lang.org/)."

default_version = "mypy==0.782"
default_version = "mypy==0.800"
default_entry_point = "mypy"
# See `mypy/rules.py`. We only use these default constraints in some situations. Technically,
# MyPy only requires 3.5+, but some popular plugins like `django-stubs` require 3.6+. Because
Expand Down
4 changes: 3 additions & 1 deletion src/python/pants/engine/collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,9 @@ class Examples(DeduplicatedCollection[Example]):
sort_input: ClassVar[bool] = False

def __init__(self, iterable: Iterable[T] = ()) -> None:
super().__init__(iterable if not self.sort_input else sorted(iterable))
super().__init__(
iterable if not self.sort_input else sorted(iterable) # type: ignore[type-var]
)

def __repr__(self) -> str:
return f"{self.__class__.__name__}({list(self._items)})"
2 changes: 1 addition & 1 deletion src/python/pants/engine/target.py
Original file line number Diff line number Diff line change
Expand Up @@ -786,7 +786,7 @@ def _get_field_set_fields_from_target(
all_expected_fields: Dict[str, Type[Field]] = {
dataclass_field.name: dataclass_field.type
for dataclass_field in dataclasses.fields(field_set)
if isinstance(dataclass_field.type, type) and issubclass(dataclass_field.type, Field) # type: ignore[unreachable]
if isinstance(dataclass_field.type, type) and issubclass(dataclass_field.type, Field)
}

return {
Expand Down
4 changes: 2 additions & 2 deletions src/python/pants/goal/run_tracker_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from pants.version import VERSION


@freeze_time(datetime.datetime(2020, 1, 1, 12, 0, 0), as_kwarg="frozen_time")
@freeze_time(datetime.datetime(2020, 1, 1, 12, 0, 0), as_kwarg="frozen_time") # type: ignore[call-arg]
def test_run_tracker_timing_output(**kwargs) -> None:
with temporary_dir() as buildroot:
with environment_as(PANTS_BUILDROOT_OVERRIDE=buildroot):
Expand All @@ -36,7 +36,7 @@ def test_run_tracker_timing_output(**kwargs) -> None:
"exit_code,expected",
[(PANTS_SUCCEEDED_EXIT_CODE, "SUCCESS"), (PANTS_FAILED_EXIT_CODE, "FAILURE")],
)
@freeze_time(datetime.datetime(2020, 1, 10, 12, 0, 1), as_kwarg="frozen_time")
@freeze_time(datetime.datetime(2020, 1, 10, 12, 0, 1), as_kwarg="frozen_time") # type: ignore[call-arg]
def test_run_information(exit_code, expected, **kwargs) -> None:
with temporary_dir() as buildroot:
with environment_as(PANTS_BUILDROOT_OVERRIDE=buildroot):
Expand Down
6 changes: 3 additions & 3 deletions src/python/pants/option/ranked_value.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from dataclasses import dataclass
from enum import Enum
from functools import total_ordering
from typing import Any, Dict, Iterator, List, Optional, Tuple, Union
from typing import Any, Dict, Iterator, List, Optional, Tuple, Union, cast


@total_ordering
Expand All @@ -27,10 +27,10 @@ def __new__(cls, rank: int, display: str) -> Rank:
member._rank = rank
return member

def __lt__(self, other: Any) -> Union["NotImplemented", bool]:
def __lt__(self, other: Any) -> bool:
if type(other) != Rank:
return NotImplemented
return self._rank < other._rank
return cast(bool, self._rank < other._rank)


Value = Union[str, int, float, None, Dict, Enum, List]
Expand Down
2 changes: 1 addition & 1 deletion src/python/pants/util/meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,6 @@ def new_setattr(self, key: str, value: Any) -> None:
cls._freeze_instance = freeze_instance
cls._unfreeze_instance = unfreeze_instance
cls.__init__ = new_init
cls.__setattr__ = new_setattr
cls.__setattr__ = new_setattr # type: ignore[assignment]

return cls

0 comments on commit 228d763

Please sign in to comment.