Skip to content

Commit

Permalink
Fix broken type hints for nested functions
Browse files Browse the repository at this point in the history
  • Loading branch information
Pebaz committed Jul 27, 2023
1 parent 927e9e3 commit c4265d7
Showing 1 changed file with 22 additions and 20 deletions.
42 changes: 22 additions & 20 deletions nimporter/nexporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,27 @@ def compile_extensions_to_c(platforms: List[str], root: Path) -> None:
return


def _is_valid_identifier(string: str) -> Union[Match[str], None, bool]:
import re
match = re.search('^[A-Za-z_][A-Z-a-z0-9_\\-]*', string)
return match and len(match.string) == len(string)


def _is_semver(string: str) -> bool:
try:
lib_name, lib_version = string.rsplit('-', maxsplit=1)
assert _is_valid_identifier(lib_name)

major, minor, patch = lib_version.split('.')
assert major.isdigit()
assert minor.isdigit()
assert patch.isdigit()

return True
except:
return False


def prevent_win32_max_path_length_error(path: Path) -> None:
"""
Nim generates C files that contain `@` symbols to encode the original path
Expand All @@ -275,25 +296,6 @@ def prevent_win32_max_path_length_error(path: Path) -> None:
That's a lot less characters!
"""

def is_valid_identifier(string: str) -> Union[Match[str], None, bool]:
import re
match = re.search('^[A-Za-z_][A-Z-a-z0-9_\\-]*', string)
return match and len(match.string) == len(string)

def is_semver(string: str) -> bool:
try:
lib_name, lib_version = string.rsplit('-', maxsplit=1)
assert is_valid_identifier(lib_name)

major, minor, patch = lib_version.split('.')
assert major.isdigit()
assert minor.isdigit()
assert patch.isdigit()

return True
except:
return False

for item in path.iterdir():
if item.is_file() and item.name.startswith('@m'):

Expand All @@ -307,7 +309,7 @@ def is_semver(string: str) -> bool:
segments = item.name.replace('@m', '').split('@s')

for segment in reversed(segments):
if is_semver(segment):
if _is_semver(segment):
index = segments.index(segment)
mod_name = '@'.join(segments[index:])
break
Expand Down

0 comments on commit c4265d7

Please sign in to comment.