File tree Expand file tree Collapse file tree 3 files changed +14
-2
lines changed Expand file tree Collapse file tree 3 files changed +14
-2
lines changed Original file line number Diff line number Diff line change
1
+ Fix a ``NoneType`` ``AttributeError`` when evaluating hashes and no hashes
2
+ are provided.
Original file line number Diff line number Diff line change @@ -200,11 +200,11 @@ def has_hash(self):
200
200
return self .hash_name is not None
201
201
202
202
def is_hash_allowed (self , hashes ):
203
- # type: (Hashes) -> bool
203
+ # type: (Optional[ Hashes] ) -> bool
204
204
"""
205
205
Return True if the link has a hash and it is allowed.
206
206
"""
207
- if not self .has_hash :
207
+ if hashes is None or not self .has_hash :
208
208
return False
209
209
# Assert non-None so mypy knows self.hash_name and self.hash are str.
210
210
assert self .hash_name is not None
Original file line number Diff line number Diff line change @@ -117,3 +117,13 @@ def test_is_hash_allowed__no_hash(self):
117
117
}
118
118
hashes = Hashes (hashes_data )
119
119
assert not link .is_hash_allowed (hashes )
120
+
121
+ @pytest .mark .parametrize ('hashes, expected' , [
122
+ (None , False ),
123
+ # Also test a success case to show the test is correct.
124
+ (Hashes ({'sha512' : [128 * 'a' ]}), True ),
125
+ ])
126
+ def test_is_hash_allowed__none_hashes (self , hashes , expected ):
127
+ url = 'https://example.com/wheel.whl#sha512={}' .format (128 * 'a' )
128
+ link = Link (url )
129
+ assert link .is_hash_allowed (hashes ) == expected
You can’t perform that action at this time.
0 commit comments