Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions src/poetry/core/_vendor/attr/__init__.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
# SPDX-License-Identifier: MIT

from __future__ import absolute_import, division, print_function

import sys

from functools import partial

from . import converters, exceptions, filters, setters, validators
from ._cmp import cmp_using
from ._config import get_run_validators, set_run_validators
from ._funcs import asdict, assoc, astuple, evolve, has, resolve_types
from ._make import (
Expand All @@ -21,7 +24,7 @@
from ._version_info import VersionInfo


__version__ = "20.3.0"
__version__ = "21.4.0"
__version_info__ = VersionInfo._from_version_string(__version__)

__title__ = "attrs"
Expand Down Expand Up @@ -52,6 +55,7 @@
"attrib",
"attributes",
"attrs",
"cmp_using",
"converters",
"evolve",
"exceptions",
Expand All @@ -71,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"))
154 changes: 154 additions & 0 deletions src/poetry/core/_vendor/attr/_cmp.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
# SPDX-License-Identifier: MIT

from __future__ import absolute_import, division, print_function

import functools

from ._compat import new_class
from ._make import _make_ne


_operation_names = {"eq": "==", "lt": "<", "le": "<=", "gt": ">", "ge": ">="}


def cmp_using(
eq=None,
lt=None,
le=None,
gt=None,
ge=None,
require_same_type=True,
class_name="Comparable",
):
"""
Create a class that can be passed into `attr.ib`'s ``eq``, ``order``, and
``cmp`` arguments to customize field comparison.
The resulting class will have a full set of ordering methods if
at least one of ``{lt, le, gt, ge}`` and ``eq`` are provided.
:param Optional[callable] eq: `callable` used to evaluate equality
of two objects.
:param Optional[callable] lt: `callable` used to evaluate whether
one object is less than another object.
:param Optional[callable] le: `callable` used to evaluate whether
one object is less than or equal to another object.
:param Optional[callable] gt: `callable` used to evaluate whether
one object is greater than another object.
:param Optional[callable] ge: `callable` used to evaluate whether
one object is greater than or equal to another object.
:param bool require_same_type: When `True`, equality and ordering methods
will return `NotImplemented` if objects are not of the same type.
:param Optional[str] class_name: Name of class. Defaults to 'Comparable'.
See `comparison` for more details.
.. versionadded:: 21.1.0
"""

body = {
"__slots__": ["value"],
"__init__": _make_init(),
"_requirements": [],
"_is_comparable_to": _is_comparable_to,
}

# Add operations.
num_order_functions = 0
has_eq_function = False

if eq is not None:
has_eq_function = True
body["__eq__"] = _make_operator("eq", eq)
body["__ne__"] = _make_ne()

if lt is not None:
num_order_functions += 1
body["__lt__"] = _make_operator("lt", lt)

if le is not None:
num_order_functions += 1
body["__le__"] = _make_operator("le", le)

if gt is not None:
num_order_functions += 1
body["__gt__"] = _make_operator("gt", gt)

if ge is not None:
num_order_functions += 1
body["__ge__"] = _make_operator("ge", ge)

type_ = new_class(class_name, (object,), {}, lambda ns: ns.update(body))

# Add same type requirement.
if require_same_type:
type_._requirements.append(_check_same_type)

# Add total ordering if at least one operation was defined.
if 0 < num_order_functions < 4:
if not has_eq_function:
# functools.total_ordering requires __eq__ to be defined,
# so raise early error here to keep a nice stack.
raise ValueError(
"eq must be define is order to complete ordering from "
"lt, le, gt, ge."
)
type_ = functools.total_ordering(type_)

return type_


def _make_init():
"""
Create __init__ method.
"""

def __init__(self, value):
"""
Initialize object with *value*.
"""
self.value = value

return __init__


def _make_operator(name, func):
"""
Create operator method.
"""

def method(self, other):
if not self._is_comparable_to(other):
return NotImplemented

result = func(self.value, other.value)
if result is NotImplemented:
return NotImplemented

return result

method.__name__ = "__%s__" % (name,)
method.__doc__ = "Return a %s b. Computed by attrs." % (
_operation_names[name],
)

return method


def _is_comparable_to(self, other):
"""
Check whether `other` is comparable to `self`.
"""
for func in self._requirements:
if not func(self, other):
return False
return True


def _check_same_type(self, other):
"""
Return True if *self* and *other* are of the same type, False otherwise.
"""
return other.value.__class__ is self.value.__class__
34 changes: 32 additions & 2 deletions src/poetry/core/_vendor/attr/_compat.py
Original file line number Diff line number Diff line change
@@ -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 All @@ -28,6 +34,15 @@
def isclass(klass):
return isinstance(klass, (type, types.ClassType))

def new_class(name, bases, kwds, exec_body):
"""
A minimal stub of types.new_class that we need for make_class.
"""
ns = {}
exec_body(ns)

return type(name, bases, ns)

# TYPE is used in exceptions, repr(int) is different on Python 2 and 3.
TYPE = "type"

Expand Down Expand Up @@ -97,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 All @@ -122,6 +136,8 @@ def isclass(klass):
def iteritems(d):
return d.items()

new_class = types.new_class

def metadata_proxy(d):
return types.MappingProxyType(dict(d))

Expand Down Expand Up @@ -229,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 src/poetry/core/_vendor/attr/_config.py
Original file line number Diff line number Diff line change
@@ -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
Loading