Skip to content
This repository has been archived by the owner on Jan 12, 2021. It is now read-only.

Commit

Permalink
Merge pull request #261 from dephell/fix-depr-warn-attrs
Browse files Browse the repository at this point in the history
fix depr warning in attrs about `cmp`
  • Loading branch information
orsinium committed Oct 8, 2019
2 parents 993a212 + 1f88cd7 commit 3799996
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 14 deletions.
2 changes: 1 addition & 1 deletion dephell/models/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from requests.auth import HTTPBasicAuth


@attr.s(cmp=True, frozen=True)
@attr.s(eq=True, order=True, frozen=True)
class Auth(HTTPBasicAuth):
hostname = attr.ib(type=str)
username = attr.ib(type=str)
Expand Down
2 changes: 1 addition & 1 deletion dephell/models/dependency.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from .marker_tracker import MarkerTracker


@attr.s(cmp=False)
@attr.s(eq=False, order=False)
class Dependency:
raw_name = attr.ib(type=str)
constraint = attr.ib(type=Constraint)
Expand Down
2 changes: 1 addition & 1 deletion dephell/models/extra_dependency.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from .groups import Groups


@attr.s(cmp=False)
@attr.s(eq=False, order=False)
class ExtraDependency(Dependency):
extra = attr.ib(type=str, default='')

Expand Down
21 changes: 20 additions & 1 deletion dephell/models/git_release.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,25 @@
from .release import Release


@attr.s(hash=False, cmp=True)
@attr.s(hash=False, eq=False, order=False)
class GitRelease(Release):
commit = attr.ib(default=None) # just for information

def __eq__(self, other) -> str:
if not isinstance(other, type(self)):
return NotImplemented
if self.name != other.name:
return False
if self.commit != other.commit:
return False
return True

def __lt__(self, other):
if not isinstance(other, type(self)):
return NotImplemented
left = (self.name, self.commit, self.version, self.time)
right = (other.name, self.commit, other.version, other.time)
return left < right

def __hash__(self) -> int:
return hash((self.name, self.commit, self.version))
34 changes: 25 additions & 9 deletions dephell/models/release.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@
from ..cached_property import cached_property


@attr.s(hash=False, cmp=True)
@attr.s(hash=False, eq=False, order=False)
class Release:
dependencies = None # type: tuple

raw_name = attr.ib(type=str, cmp=False)
version = attr.ib(converter=parse, cmp=True) # typing: ignore
time = attr.ib(repr=False, hash=False) # upload_time
python = attr.ib(default=None, repr=False, cmp=False) # requires_python
hashes = attr.ib(factory=tuple, repr=False, cmp=False) # digests/sha256
raw_name = attr.ib(type=str)
version = attr.ib(converter=parse) # type: ignore
time = attr.ib(repr=False) # upload_time
python = attr.ib(default=None, repr=False) # requires_python
hashes = attr.ib(factory=tuple, repr=False) # digests/sha256

extra = attr.ib(type=Optional[str], default=None)

Expand All @@ -47,8 +47,24 @@ def from_response(cls, name, version, info, extra=None):
def name(self) -> str:
return canonicalize_name(self.raw_name)

def __hash__(self) -> int:
return hash((self.name, self.version))

def __eq__(self, other) -> str:
if not isinstance(other, type(self)):
return NotImplemented
if self.name != other.name:
return False
if self.version != other.version:
return False
return True

def __lt__(self, other) -> str:
if not isinstance(other, type(self)):
return NotImplemented
left = (self.name, self.version, self.time)
right = (other.name, other.version, other.time)
return left < right

def __str__(self):
return '{name}=={version}'.format(name=self.raw_name, version=self.version)

def hash(self):
return hash((self.name, self.version))
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ dephell = "dephell.cli:entrypoint"
python = ">=3.5"
aiohttp = "*"
appdirs = "*"
attrs = "*"
attrs = ">=19.1.0"
bowler = {python = ">=3.6",version = "*"}
bowler-py35 = {version = ">=0.9.1",python = "<3.6"}
cerberus = ">=1.3"
Expand Down

0 comments on commit 3799996

Please sign in to comment.