Skip to content

Commit

Permalink
Make Requirement hashable
Browse files Browse the repository at this point in the history
  • Loading branch information
abravalheri committed Jan 16, 2022
1 parent ff906dc commit 215c172
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion packaging/requirements.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import re
import string
import urllib.parse
from typing import List, Optional as TOptional, Set
from typing import Any, List, Optional as TOptional, Set

from pyparsing import ( # noqa
Combine,
Expand Down Expand Up @@ -144,3 +144,9 @@ def __str__(self) -> str:

def __repr__(self) -> str:
return f"<Requirement('{self}')>"

def __hash__(self) -> int:
return hash((self.__class__.__name__, str(self)))

def __eq__(self, other: Any) -> bool:
return bool(self.__class__ == other.__class__ and str(self) == str(other))

0 comments on commit 215c172

Please sign in to comment.