Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Python 3 syntax back to 3.0 #261

Merged
merged 13 commits into from
Mar 20, 2020
Prev Previous commit
Next Next commit
Simplify allowed python_versions, add 3.3
  • Loading branch information
thatch committed Mar 12, 2020
commit 2a3703ec0adeb98cbb572fee3ece108fdc3c682a
16 changes: 9 additions & 7 deletions libcst/_parser/types/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ def __repr__(self) -> str:
return str(self)


KNOWN_PYTHON_VERSION_STRINGS = ["3.3", "3.5", "3.6", "3.7", "3.8"]


@add_slots
@dataclass(frozen=True)
class PartialParserConfig:
Expand All @@ -84,7 +87,7 @@ class PartialParserConfig:
#: run LibCST. For example, you can parse code as 3.7 with a CPython 3.6
#: interpreter.
#:
#: Currently, only Python 3.5, 3.6, 3.7 and 3.8 syntax is supported.
#: Currently, only Python 3.3, 3.5, 3.6, 3.7 and 3.8 syntax is supported.
python_version: Union[str, AutoConfig] = AutoConfig.token

#: A named tuple with the ``major`` and ``minor`` Python version numbers. This is
Expand Down Expand Up @@ -121,15 +124,14 @@ def __post_init__(self) -> None:

# Once we add support for more versions of Python, we can change this to detect
# the supported version range.
if parsed_python_version not in (
PythonVersionInfo(3, 5),
PythonVersionInfo(3, 6),
PythonVersionInfo(3, 7),
PythonVersionInfo(3, 8),
if not any(
parsed_python_version == parse_version_string(v)
for v in KNOWN_PYTHON_VERSION_STRINGS
):
comma_versions = ", ".join(KNOWN_PYTHON_VERSION_STRINGS)
raise ValueError(
"LibCST can only parse code using one of the following versions of "
+ "Python's grammar: 3.5, 3.6, 3.7, 3.8. More versions may be "
+ f"Python's grammar: {comma_versions}. More versions may be "
+ "supported by future releases."
)

Expand Down