Skip to content

Commit

Permalink
Annotate the public interface (#350)
Browse files Browse the repository at this point in the history
This adds annotations to public attributes of the `Requirement`
class so that type checkers are not required ( :) to infer their type.

Co-authored-by: Pradyun Gedam <3275593+pradyunsg@users.noreply.github.com>
Co-authored-by: Brett Cannon <brett@python.org>
  • Loading branch information
3 people committed Dec 2, 2020
1 parent fc86d7e commit a6407e3
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions packaging/requirements.py
Expand Up @@ -22,7 +22,7 @@


if TYPE_CHECKING: # pragma: no cover
from typing import List
from typing import List, Optional as TOptional, Set


class InvalidRequirement(ValueError):
Expand Down Expand Up @@ -109,7 +109,7 @@ def __init__(self, requirement_string):
)
)

self.name = req.name
self.name = req.name # type: str
if req.url:
parsed_url = urlparse.urlparse(req.url)
if parsed_url.scheme == "file":
Expand All @@ -119,12 +119,12 @@ def __init__(self, requirement_string):
not parsed_url.scheme and not parsed_url.netloc
):
raise InvalidRequirement("Invalid URL: {0}".format(req.url))
self.url = req.url
self.url = req.url # type: TOptional[str]
else:
self.url = None
self.extras = set(req.extras.asList() if req.extras else [])
self.specifier = SpecifierSet(req.specifier)
self.marker = req.marker if req.marker else None
self.extras = set(req.extras.asList() if req.extras else []) # type: Set[str]
self.specifier = SpecifierSet(req.specifier) # type: SpecifierSet
self.marker = req.marker if req.marker else None # type: TOptional[Marker]

def __str__(self):
# type: () -> str
Expand Down

0 comments on commit a6407e3

Please sign in to comment.