Skip to content

Commit c9cfec8

Browse files
authored
Upgrade attrs to unreleased @ 947bfb54. (#1780)
This picks up a fix for python-attrs/attrs#909 which allows simplification of `pex.dist_metadata.Requirement`.
1 parent e707bdc commit c9cfec8

42 files changed

Lines changed: 1010 additions & 308 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

pex/dist_metadata.py

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -449,21 +449,13 @@ def from_packaging_requirement(cls, requirement):
449449
url = attr.ib(default=None) # type: Optional[str]
450450
extras = attr.ib(default=frozenset()) # type: FrozenSet[str]
451451
specifier = attr.ib(factory=SpecifierSet) # type: SpecifierSet
452-
marker = attr.ib(default=None, eq=False) # type: Optional[Marker]
452+
marker = attr.ib(default=None, eq=str) # type: Optional[Marker]
453453

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

464457
def __attrs_post_init__(self):
465458
object.__setattr__(self, "project_name", ProjectName(self.name))
466-
object.__setattr__(self, "_marker_for_eq_and_hash", str(self.marker))
467459

468460
parts = [self.name]
469461
if self.extras:

pex/vendor/__init__.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,14 @@ def iter_vendor_specs():
144144
# We use this for a better @dataclass that is also Python2.7 and PyPy compatible.
145145
# N.B.: The `[testenv:typecheck]` section in `tox.ini` should have its deps list updated to
146146
# reflect this attrs version.
147-
yield VendorSpec.pinned("attrs", "21.2.0")
147+
# This vcs version gets us the fix in https://github.com/python-attrs/attrs/pull/909
148+
# which is not yet released.
149+
yield VendorSpec.git(
150+
repo="https://github.com/python-attrs/attrs",
151+
commit="947bfb542104209a587280701d8cb389c813459d",
152+
project_name="attrs",
153+
rewrite=True,
154+
)
148155

149156
# We use this via pex.third_party at runtime to check for compatible wheel tags and at build
150157
# time to implement resolving distributions from a PEX repository.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"record_relpath": "attrs-21.2.0.dist-info/RECORD", "stash_dir": ".prefix"}
1+
{"record_relpath": "attrs-21.5.0.dev0.dist-info/RECORD", "stash_dir": ".prefix"}

pex/vendor/_vendored/attrs/attr/__init__.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# SPDX-License-Identifier: MIT
2+
13
from __future__ import absolute_import, division, print_function
24

35
import sys
@@ -22,7 +24,7 @@
2224
from ._version_info import VersionInfo
2325

2426

25-
__version__ = "21.2.0"
27+
__version__ = "21.5.0.dev0"
2628
__version_info__ = VersionInfo._from_version_string(__version__)
2729

2830
__title__ = "attrs"
@@ -73,6 +75,6 @@
7375
]
7476

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

78-
__all__.extend((define, field, frozen, mutable))
80+
__all__.extend(("define", "field", "frozen", "mutable"))

pex/vendor/_vendored/attrs/attr/__init__.pyi

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ from . import setters as setters
2424
from . import validators as validators
2525
from ._version_info import VersionInfo
2626

27-
2827
__version__: str
2928
__version_info__: VersionInfo
3029
__title__: str
@@ -49,7 +48,10 @@ _OnSetAttrType = Callable[[Any, Attribute[Any], Any], Any]
4948
_OnSetAttrArgType = Union[
5049
_OnSetAttrType, List[_OnSetAttrType], setters._NoOpType
5150
]
52-
_FieldTransformer = Callable[[type, List[Attribute[Any]]], List[Attribute[Any]]]
51+
_FieldTransformer = Callable[
52+
[type, List[Attribute[Any]]], List[Attribute[Any]]
53+
]
54+
_CompareWithType = Callable[[Any, Any], bool]
5355
# FIXME: in reality, if multiple validators are passed they must be in a list
5456
# or tuple, but those are invariant and so would prevent subtypes of
5557
# _ValidatorType from working when passed in a list or tuple.
@@ -64,7 +66,6 @@ NOTHING: object
6466
# Work around mypy issue #4554 in the common case by using an overload.
6567
if sys.version_info >= (3, 8):
6668
from typing import Literal
67-
6869
@overload
6970
def Factory(factory: Callable[[], _T]) -> _T: ...
7071
@overload
@@ -77,6 +78,7 @@ if sys.version_info >= (3, 8):
7778
factory: Callable[[], _T],
7879
takes_self: Literal[False],
7980
) -> _T: ...
81+
8082
else:
8183
@overload
8284
def Factory(factory: Callable[[], _T]) -> _T: ...
@@ -117,7 +119,6 @@ class Attribute(Generic[_T]):
117119
type: Optional[Type[_T]]
118120
kw_only: bool
119121
on_setattr: _OnSetAttrType
120-
121122
def evolve(self, **changes: Any) -> "Attribute[Any]": ...
122123

123124
# NOTE: We had several choices for the annotation to use for type arg:
@@ -315,6 +316,7 @@ def attrs(
315316
getstate_setstate: Optional[bool] = ...,
316317
on_setattr: Optional[_OnSetAttrArgType] = ...,
317318
field_transformer: Optional[_FieldTransformer] = ...,
319+
match_args: bool = ...,
318320
) -> _C: ...
319321
@overload
320322
@__dataclass_transform__(order_default=True, field_descriptors=(attrib, field))
@@ -341,6 +343,7 @@ def attrs(
341343
getstate_setstate: Optional[bool] = ...,
342344
on_setattr: Optional[_OnSetAttrArgType] = ...,
343345
field_transformer: Optional[_FieldTransformer] = ...,
346+
match_args: bool = ...,
344347
) -> Callable[[_C], _C]: ...
345348
@overload
346349
@__dataclass_transform__(field_descriptors=(attrib, field))
@@ -365,6 +368,7 @@ def define(
365368
getstate_setstate: Optional[bool] = ...,
366369
on_setattr: Optional[_OnSetAttrArgType] = ...,
367370
field_transformer: Optional[_FieldTransformer] = ...,
371+
match_args: bool = ...,
368372
) -> _C: ...
369373
@overload
370374
@__dataclass_transform__(field_descriptors=(attrib, field))
@@ -389,6 +393,7 @@ def define(
389393
getstate_setstate: Optional[bool] = ...,
390394
on_setattr: Optional[_OnSetAttrArgType] = ...,
391395
field_transformer: Optional[_FieldTransformer] = ...,
396+
match_args: bool = ...,
392397
) -> Callable[[_C], _C]: ...
393398

394399
mutable = define
@@ -442,13 +447,17 @@ def make_class(
442447
# these:
443448
# https://github.com/python/mypy/issues/4236
444449
# https://github.com/python/typing/issues/253
450+
# XXX: remember to fix attrs.asdict/astuple too!
445451
def asdict(
446452
inst: Any,
447453
recurse: bool = ...,
448454
filter: Optional[_FilterType[Any]] = ...,
449455
dict_factory: Type[Mapping[Any, Any]] = ...,
450456
retain_collection_types: bool = ...,
451-
value_serializer: Optional[Callable[[type, Attribute[Any], Any], Any]] = ...,
457+
value_serializer: Optional[
458+
Callable[[type, Attribute[Any], Any], Any]
459+
] = ...,
460+
tuple_keys: Optional[bool] = ...,
452461
) -> Dict[str, Any]: ...
453462

454463
# TODO: add support for returning NamedTuple from the mypy plugin

pex/vendor/_vendored/attrs/attr/_cmp.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# SPDX-License-Identifier: MIT
2+
13
from __future__ import absolute_import, division, print_function
24

35
import functools

pex/vendor/_vendored/attrs/attr/_cmp.pyi

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ from typing import Type
22

33
from . import _CompareWithType
44

5-
65
def cmp_using(
76
eq: Optional[_CompareWithType],
87
lt: Optional[_CompareWithType],

pex/vendor/_vendored/attrs/attr/_compat.py

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,22 @@
1+
# SPDX-License-Identifier: MIT
2+
13
from __future__ import absolute_import, division, print_function
24

35
import platform
46
import sys
7+
import threading
58
import types
69
import warnings
710

811

912
PY2 = sys.version_info[0] == 2
1013
PYPY = platform.python_implementation() == "PyPy"
14+
PY36 = sys.version_info[:2] >= (3, 6)
15+
HAS_F_STRINGS = PY36
16+
PY310 = sys.version_info[:2] >= (3, 10)
1117

1218

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

109-
110115
else: # Python 3 and later.
111116
from collections.abc import Mapping, Sequence # noqa
112117

@@ -240,3 +245,17 @@ def func():
240245

241246

242247
set_closure_cell = make_set_closure_cell()
248+
249+
# Thread-local global to track attrs instances which are already being repr'd.
250+
# This is needed because there is no other (thread-safe) way to pass info
251+
# about the instances that are already being repr'd through the call stack
252+
# in order to ensure we don't perform infinite recursion.
253+
#
254+
# For instance, if an instance contains a dict which contains that instance,
255+
# we need to know that we're already repr'ing the outside instance from within
256+
# the dict's repr() call.
257+
#
258+
# This lives here rather than in _make.py so that the functions in _make.py
259+
# don't have a direct reference to the thread-local in their globals dict.
260+
# If they have such a reference, it breaks cloudpickle.
261+
repr_context = threading.local()

pex/vendor/_vendored/attrs/attr/_config.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# SPDX-License-Identifier: MIT
2+
13
from __future__ import absolute_import, division, print_function
24

35

@@ -9,6 +11,10 @@
911
def set_run_validators(run):
1012
"""
1113
Set whether or not validators are run. By default, they are run.
14+
15+
.. deprecated:: 21.3.0 It will not be removed, but it also will not be
16+
moved to new ``attrs`` namespace. Use `attrs.validators.set_disabled()`
17+
instead.
1218
"""
1319
if not isinstance(run, bool):
1420
raise TypeError("'run' must be bool.")
@@ -19,5 +25,9 @@ def set_run_validators(run):
1925
def get_run_validators():
2026
"""
2127
Return whether or not validators are run.
28+
29+
.. deprecated:: 21.3.0 It will not be removed, but it also will not be
30+
moved to new ``attrs`` namespace. Use `attrs.validators.get_disabled()`
31+
instead.
2232
"""
2333
return _run_validators

0 commit comments

Comments
 (0)