MCPcopy Create free account
hub / github.com/psf/black / parse_req_python_version

Function parse_req_python_version

src/black/files.py:156–168  ·  view source on GitHub ↗

Parse a version string (i.e. ``"3.7"``) to a list of TargetVersion. If parsing fails, will raise a packaging.version.InvalidVersion error. If the parsed version cannot be mapped to a valid TargetVersion, returns None.

(requires_python: str)

Source from the content-addressed store, hash-verified

154
155
156def parse_req_python_version(requires_python: str) -> Optional[List[TargetVersion]]:
157 """Parse a version string (i.e. ``"3.7"``) to a list of TargetVersion.
158
159 If parsing fails, will raise a packaging.version.InvalidVersion error.
160 If the parsed version cannot be mapped to a valid TargetVersion, returns None.
161 """
162 version = Version(requires_python)
163 if version.release[0] != 3:
164 return None
165 try:
166 return [TargetVersion(version.release[1])]
167 except (IndexError, ValueError):
168 return None
169
170
171def parse_req_python_specifier(requires_python: str) -> Optional[List[TargetVersion]]:

Callers 1

infer_target_versionFunction · 0.85

Calls 1

TargetVersionClass · 0.90

Tested by

no test coverage detected