Skip to content

Commit 652a402

Browse files
authored
Merge pull request #4 from dephell/fix-hash
Fix hashing for operations
2 parents 9c10d03 + 38afa06 commit 652a402

8 files changed

Lines changed: 33 additions & 12 deletions

File tree

.travis.yml

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
11
language: python
22

3+
# do not run Travis for PR's twice (as for push and as for PR)
4+
branches:
5+
only:
6+
- master
7+
38
before_install:
49
# show a little bit more information about environment
510
- sudo apt-get install -y tree
611
- env
712
- tree
813
# install DepHell
914
# https://github.com/travis-ci/travis-ci/issues/8589
10-
- curl https://raw.githubusercontent.com/dephell/dephell/master/install.py | /opt/python/3.6/bin/python
15+
- curl https://raw.githubusercontent.com/dephell/dephell/master/install.py | /opt/python/3.6.7/bin/python
1116
- dephell inspect self
1217
install:
1318
- dephell venv create --env=$ENV --python="/opt/python/$TRAVIS_PYTHON_VERSION/bin/python"
@@ -19,14 +24,14 @@ matrix:
1924
include:
2025
- python: "3.5"
2126
env: ENV=pytest
22-
- python: "3.6"
27+
- python: "3.6.7"
2328
env: ENV=pytest
2429
- python: "3.7-dev"
2530
env: ENV=pytest
2631
- python: "pypy3.5"
2732
env: ENV=pytest
2833

29-
- python: "3.6"
34+
- python: "3.7"
3035
env: ENV=flake8
31-
- python: "3.6"
36+
- python: "3.7"
3237
env: ENV=typing

dephell_markers/_marker/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# app
12
from ._base import BaseMarker
23
from ._string import StringMarker
34
from ._version import VersionMarker

dephell_markers/_marker/_base.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
1+
# built-in
2+
from typing import Optional, Set
3+
14
# external
25
import attr
36
from packaging.markers import Value, Variable
4-
from typing import Optional, Set
57

68
# app
79
from .._cached_property import cached_property
810
from .._constants import ALIASES
911

1012

11-
@attr.s(cmp=False)
13+
@attr.s(eq=False, order=False)
1214
class BaseMarker:
1315
lhs = attr.ib()
1416
op = attr.ib()

dephell_markers/_marker/_version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88

99
# app
1010
from .._cached_property import cached_property
11-
from ._base import BaseMarker
1211
from .._constants import REVERSED_OPERATIONS
12+
from ._base import BaseMarker
1313

1414

1515
class VersionMarker(BaseMarker):

dephell_markers/_markers.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
# built-in
22
from copy import copy
3-
from typing import Optional, Union, Set, Type
3+
from typing import Optional, Set, Type, Union
44

55
# external
66
from dephell_specifier import RangeSpecifier
77
from packaging import markers as packaging
8-
from packaging.markers import Variable, Op, Value
8+
from packaging.markers import Op, Value, Variable
99

1010
# app
11-
from ._marker import BaseMarker, StringMarker, VersionMarker
12-
from ._operation import OrMarker, AndMarker, Operation
1311
from ._constants import STRING_VARIABLES, VERSION_VARIABLES
12+
from ._marker import BaseMarker, StringMarker, VersionMarker
13+
from ._operation import AndMarker, Operation, OrMarker
1414

1515

1616
class Markers:

dephell_markers/_operation/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# app
12
from ._and import AndMarker
23
from ._base import Operation
34
from ._or import OrMarker

dephell_markers/_operation/_base.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# built-in
22
from typing import Optional, Set
33

4+
# app
45
from .._cached_property import cached_property
56

67

@@ -88,7 +89,7 @@ def __eq__(self, other):
8889
return self.op == other.op and set(self.nodes) == set(other.nodes)
8990

9091
def __hash__(self):
91-
return hash(self.nodes)
92+
return hash(tuple(self.nodes))
9293

9394
def __str__(self):
9495
sep = ' ' + self.op + ' '

tests/test_markers.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,3 +202,14 @@ def test_empty():
202202
m &= Markers('os_name == "nt"')
203203
assert str(m) == 'os_name == "nt"'
204204
assert bool(m) is True
205+
206+
207+
# https://github.com/dephell/dephell/issues/256
208+
def test_dedup():
209+
text = """
210+
python_version >= "3.4"
211+
and (sys_platform == "linux2" or sys_platform == "linux")
212+
or python_version >= "3.5" and python_version < "4.0"
213+
"""
214+
m = Markers(text)
215+
assert str(m).split() == text.split()

0 commit comments

Comments
 (0)