Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade attrs to unreleased @ 947bfb54. #1780

Merged
merged 3 commits into from May 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 1 addition & 9 deletions pex/dist_metadata.py
Expand Up @@ -449,21 +449,13 @@ def from_packaging_requirement(cls, requirement):
url = attr.ib(default=None) # type: Optional[str]
extras = attr.ib(default=frozenset()) # type: FrozenSet[str]
specifier = attr.ib(factory=SpecifierSet) # type: SpecifierSet
marker = attr.ib(default=None, eq=False) # type: Optional[Marker]
marker = attr.ib(default=None, eq=str) # type: Optional[Marker]

project_name = attr.ib(init=False, repr=False) # type: ProjectName

# We should just be able to set `eq=str` on the marker field, but there is a bug in the
# generated `__hash__` method for this case. It is fixed here in Jan 2022 but the latest
# release (21.4.0) is still from Dec 2021 as of this writing:
# https://github.com/python-attrs/attrs/pull/909
_marker_for_eq_and_hash = attr.ib(init=False, repr=False) # type: str

_str = attr.ib(init=False, eq=False, repr=False) # type: str

def __attrs_post_init__(self):
object.__setattr__(self, "project_name", ProjectName(self.name))
object.__setattr__(self, "_marker_for_eq_and_hash", str(self.marker))

parts = [self.name]
if self.extras:
Expand Down
9 changes: 8 additions & 1 deletion pex/vendor/__init__.py
Expand Up @@ -144,7 +144,14 @@ def iter_vendor_specs():
# We use this for a better @dataclass that is also Python2.7 and PyPy compatible.
# N.B.: The `[testenv:typecheck]` section in `tox.ini` should have its deps list updated to
# reflect this attrs version.
yield VendorSpec.pinned("attrs", "21.2.0")
# This vcs version gets us the fix in https://github.com/python-attrs/attrs/pull/909
# which is not yet released.
yield VendorSpec.git(
repo="https://github.com/python-attrs/attrs",
commit="947bfb542104209a587280701d8cb389c813459d",
project_name="attrs",
rewrite=True,
)

# We use this via pex.third_party at runtime to check for compatible wheel tags and at build
# time to implement resolving distributions from a PEX repository.
Expand Down
2 changes: 1 addition & 1 deletion pex/vendor/_vendored/attrs/.layout.json
@@ -1 +1 @@
{"record_relpath": "attrs-21.2.0.dist-info/RECORD", "stash_dir": ".prefix"}
{"record_relpath": "attrs-21.5.0.dev0.dist-info/RECORD", "stash_dir": ".prefix"}
8 changes: 5 additions & 3 deletions pex/vendor/_vendored/attrs/attr/__init__.py
@@ -1,3 +1,5 @@
# SPDX-License-Identifier: MIT

from __future__ import absolute_import, division, print_function

import sys
Expand All @@ -22,7 +24,7 @@
from ._version_info import VersionInfo


__version__ = "21.2.0"
__version__ = "21.5.0.dev0"
__version_info__ = VersionInfo._from_version_string(__version__)

__title__ = "attrs"
Expand Down Expand Up @@ -73,6 +75,6 @@
]

if sys.version_info[:2] >= (3, 6):
from ._next_gen import define, field, frozen, mutable
from ._next_gen import define, field, frozen, mutable # noqa: F401

__all__.extend((define, field, frozen, mutable))
__all__.extend(("define", "field", "frozen", "mutable"))
19 changes: 14 additions & 5 deletions pex/vendor/_vendored/attrs/attr/__init__.pyi
Expand Up @@ -24,7 +24,6 @@ from . import setters as setters
from . import validators as validators
from ._version_info import VersionInfo


__version__: str
__version_info__: VersionInfo
__title__: str
Expand All @@ -49,7 +48,10 @@ _OnSetAttrType = Callable[[Any, Attribute[Any], Any], Any]
_OnSetAttrArgType = Union[
_OnSetAttrType, List[_OnSetAttrType], setters._NoOpType
]
_FieldTransformer = Callable[[type, List[Attribute[Any]]], List[Attribute[Any]]]
_FieldTransformer = Callable[
[type, List[Attribute[Any]]], List[Attribute[Any]]
]
_CompareWithType = Callable[[Any, Any], bool]
# FIXME: in reality, if multiple validators are passed they must be in a list
# or tuple, but those are invariant and so would prevent subtypes of
# _ValidatorType from working when passed in a list or tuple.
Expand All @@ -64,7 +66,6 @@ NOTHING: object
# Work around mypy issue #4554 in the common case by using an overload.
if sys.version_info >= (3, 8):
from typing import Literal

@overload
def Factory(factory: Callable[[], _T]) -> _T: ...
@overload
Expand All @@ -77,6 +78,7 @@ if sys.version_info >= (3, 8):
factory: Callable[[], _T],
takes_self: Literal[False],
) -> _T: ...

else:
@overload
def Factory(factory: Callable[[], _T]) -> _T: ...
Expand Down Expand Up @@ -117,7 +119,6 @@ class Attribute(Generic[_T]):
type: Optional[Type[_T]]
kw_only: bool
on_setattr: _OnSetAttrType

def evolve(self, **changes: Any) -> "Attribute[Any]": ...

# NOTE: We had several choices for the annotation to use for type arg:
Expand Down Expand Up @@ -315,6 +316,7 @@ def attrs(
getstate_setstate: Optional[bool] = ...,
on_setattr: Optional[_OnSetAttrArgType] = ...,
field_transformer: Optional[_FieldTransformer] = ...,
match_args: bool = ...,
) -> _C: ...
@overload
@__dataclass_transform__(order_default=True, field_descriptors=(attrib, field))
Expand All @@ -341,6 +343,7 @@ def attrs(
getstate_setstate: Optional[bool] = ...,
on_setattr: Optional[_OnSetAttrArgType] = ...,
field_transformer: Optional[_FieldTransformer] = ...,
match_args: bool = ...,
) -> Callable[[_C], _C]: ...
@overload
@__dataclass_transform__(field_descriptors=(attrib, field))
Expand All @@ -365,6 +368,7 @@ def define(
getstate_setstate: Optional[bool] = ...,
on_setattr: Optional[_OnSetAttrArgType] = ...,
field_transformer: Optional[_FieldTransformer] = ...,
match_args: bool = ...,
) -> _C: ...
@overload
@__dataclass_transform__(field_descriptors=(attrib, field))
Expand All @@ -389,6 +393,7 @@ def define(
getstate_setstate: Optional[bool] = ...,
on_setattr: Optional[_OnSetAttrArgType] = ...,
field_transformer: Optional[_FieldTransformer] = ...,
match_args: bool = ...,
) -> Callable[[_C], _C]: ...

mutable = define
Expand Down Expand Up @@ -442,13 +447,17 @@ def make_class(
# these:
# https://github.com/python/mypy/issues/4236
# https://github.com/python/typing/issues/253
# XXX: remember to fix attrs.asdict/astuple too!
def asdict(
inst: Any,
recurse: bool = ...,
filter: Optional[_FilterType[Any]] = ...,
dict_factory: Type[Mapping[Any, Any]] = ...,
retain_collection_types: bool = ...,
value_serializer: Optional[Callable[[type, Attribute[Any], Any], Any]] = ...,
value_serializer: Optional[
Callable[[type, Attribute[Any], Any], Any]
] = ...,
tuple_keys: Optional[bool] = ...,
) -> Dict[str, Any]: ...

# TODO: add support for returning NamedTuple from the mypy plugin
Expand Down
2 changes: 2 additions & 0 deletions pex/vendor/_vendored/attrs/attr/_cmp.py
@@ -1,3 +1,5 @@
# SPDX-License-Identifier: MIT

from __future__ import absolute_import, division, print_function

import functools
Expand Down
1 change: 0 additions & 1 deletion pex/vendor/_vendored/attrs/attr/_cmp.pyi
Expand Up @@ -2,7 +2,6 @@ from typing import Type

from . import _CompareWithType


def cmp_using(
eq: Optional[_CompareWithType],
lt: Optional[_CompareWithType],
Expand Down
23 changes: 21 additions & 2 deletions pex/vendor/_vendored/attrs/attr/_compat.py
@@ -1,16 +1,22 @@
# SPDX-License-Identifier: MIT

from __future__ import absolute_import, division, print_function

import platform
import sys
import threading
import types
import warnings


PY2 = sys.version_info[0] == 2
PYPY = platform.python_implementation() == "PyPy"
PY36 = sys.version_info[:2] >= (3, 6)
HAS_F_STRINGS = PY36
PY310 = sys.version_info[:2] >= (3, 10)


if PYPY or sys.version_info[:2] >= (3, 6):
if PYPY or PY36:
ordered_dict = dict
else:
from collections import OrderedDict
Expand Down Expand Up @@ -106,7 +112,6 @@ def just_warn(*args, **kw): # pragma: no cover
consequences of not setting the cell on Python 2.
"""


else: # Python 3 and later.
from collections.abc import Mapping, Sequence # noqa

Expand Down Expand Up @@ -240,3 +245,17 @@ def func():


set_closure_cell = make_set_closure_cell()

# Thread-local global to track attrs instances which are already being repr'd.
# This is needed because there is no other (thread-safe) way to pass info
# about the instances that are already being repr'd through the call stack
# in order to ensure we don't perform infinite recursion.
#
# For instance, if an instance contains a dict which contains that instance,
# we need to know that we're already repr'ing the outside instance from within
# the dict's repr() call.
#
# This lives here rather than in _make.py so that the functions in _make.py
# don't have a direct reference to the thread-local in their globals dict.
# If they have such a reference, it breaks cloudpickle.
repr_context = threading.local()
10 changes: 10 additions & 0 deletions pex/vendor/_vendored/attrs/attr/_config.py
@@ -1,3 +1,5 @@
# SPDX-License-Identifier: MIT

from __future__ import absolute_import, division, print_function


Expand All @@ -9,6 +11,10 @@
def set_run_validators(run):
"""
Set whether or not validators are run. By default, they are run.

.. deprecated:: 21.3.0 It will not be removed, but it also will not be
moved to new ``attrs`` namespace. Use `attrs.validators.set_disabled()`
instead.
"""
if not isinstance(run, bool):
raise TypeError("'run' must be bool.")
Expand All @@ -19,5 +25,9 @@ def set_run_validators(run):
def get_run_validators():
"""
Return whether or not validators are run.

.. deprecated:: 21.3.0 It will not be removed, but it also will not be
moved to new ``attrs`` namespace. Use `attrs.validators.get_disabled()`
instead.
"""
return _run_validators