Skip to content

Commit

Permalink
fix cc comment
Browse files Browse the repository at this point in the history
  • Loading branch information
tserg committed Apr 8, 2024
1 parent db395a2 commit 132b4c1
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions vyper/ast/pre_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@
from vyper.typing import ModificationOffsets, ParserPosition


def validate_version_pragma(version_str: str, code: str, start: ParserPosition) -> None:
def validate_version_pragma(version_str: str, full_source_code: str, start: ParserPosition) -> None:
"""
Validates a version pragma directive against the current compiler version.
"""
from vyper import __version__

if len(version_str) == 0:
raise VersionException("Version specification cannot be empty", code, *start)
raise VersionException("Version specification cannot be empty", full_source_code, *start)

# X.Y.Z or vX.Y.Z => ==X.Y.Z, ==vX.Y.Z
if re.match("[v0-9]", version_str):
Expand All @@ -34,14 +34,16 @@ def validate_version_pragma(version_str: str, code: str, start: ParserPosition)
spec = SpecifierSet(version_str)
except InvalidSpecifier:
raise VersionException(
f'Version specification "{version_str}" is not a valid PEP440 specifier', code, *start
f'Version specification "{version_str}" is not a valid PEP440 specifier',
full_source_code,
*start,
)

if not spec.contains(__version__, prereleases=True):
raise VersionException(
f'Version specification "{version_str}" is not compatible '
f'with compiler version "{__version__}"',
code,
full_source_code,
*start,
)

Expand Down Expand Up @@ -177,7 +179,7 @@ def pre_parse(code: str) -> tuple[Settings, ModificationOffsets, dict, str]:
if settings.compiler_version is not None:
raise StructureException("compiler version specified twice!", start)
compiler_version = contents.removeprefix("@version ").strip()
validate_version_pragma(compiler_version, line, start)
validate_version_pragma(compiler_version, code, start)
settings.compiler_version = compiler_version

if contents.startswith("pragma "):
Expand All @@ -186,7 +188,7 @@ def pre_parse(code: str) -> tuple[Settings, ModificationOffsets, dict, str]:
if settings.compiler_version is not None:
raise StructureException("pragma version specified twice!", start)
compiler_version = pragma.removeprefix("version ").strip()
validate_version_pragma(compiler_version, line, start)
validate_version_pragma(compiler_version, code, start)
settings.compiler_version = compiler_version

elif pragma.startswith("optimize "):
Expand Down

0 comments on commit 132b4c1

Please sign in to comment.