def test_get_typeshed_directories(): def get_dirs(version_info): return { d.replace(typeshed.TYPESHED_PATH, '').lstrip(os.path.sep) for d in typeshed._get_typeshed_directories(version_info) } def transform(set_): return {x.replace('/', os.path.sep) for x in set_} dirs = get_dirs(PythonVersionInfo(2, 7)) assert dirs == transform( {'stdlib/2and3', 'stdlib/2', 'third_party/2and3', 'third_party/2'}) dirs = get_dirs(PythonVersionInfo(3, 4)) assert dirs == transform( {'stdlib/2and3', 'stdlib/3', 'third_party/2and3', 'third_party/3'}) dirs = get_dirs(PythonVersionInfo(3, 5)) assert dirs == transform({ 'stdlib/2and3', 'stdlib/3', 'stdlib/3.5', 'third_party/2and3', 'third_party/3', 'third_party/3.5' }) dirs = get_dirs(PythonVersionInfo(3, 6)) assert dirs == transform({ 'stdlib/2and3', 'stdlib/3', 'stdlib/3.5', 'stdlib/3.6', 'third_party/2and3', 'third_party/3', 'third_party/3.5', 'third_party/3.6' })
def test_get_typeshed_directories(): def get_dirs(version_info): return { p.path.replace(str(typeshed.TYPESHED_PATH), '').lstrip(os.path.sep) for p in typeshed._get_typeshed_directories(version_info) } def transform(set_): return {x.replace('/', os.path.sep) for x in set_} dirs = get_dirs(PythonVersionInfo(3, 7)) assert dirs == transform({ 'stdlib/2and3', 'stdlib/3', 'stdlib/3.7', 'third_party/2and3', 'third_party/3', 'third_party/3.7' })
def __post_init__(self) -> None: raw_python_version = self.python_version # `parse_version_string` will raise a ValueError if the version is invalid. # # We use object.__setattr__ because the dataclass is frozen. See: # https://docs.python.org/3/library/dataclasses.html#frozen-instances # This should be safe behavior inside of `__post_init__`. parsed_python_version = parse_version_string( # TODO: We currently hardcode support for Py3.7 both in our grammar productions and in # our tokenizer config. If we want to support multiple versions, we will need to switch # on version-pinned grammar productions and also fix Parso's tokenizer to allow for # 3.6 and below handling of ASYNC/AWAIT. This should be changed back to None once we # support multiple versions, so that parso can derive the version from `sys.version_info` "3.7" if isinstance(raw_python_version, AutoConfig ) else raw_python_version) # Once we add support for more versions of Python, we can change this to detect # the supported version range. if parsed_python_version != PythonVersionInfo(3, 7): raise ValueError( "LibCST can only parse code using Python 3.7's grammar. More versions " + "may be supported by future releases.") object.__setattr__(self, "parsed_python_version", parsed_python_version) encoding = self.encoding if not isinstance(encoding, AutoConfig): try: codecs.lookup(encoding) except LookupError: raise ValueError( f"{repr(encoding)} is not a supported encoding") newline = self.default_newline if (not isinstance(newline, AutoConfig) and NEWLINE_RE.fullmatch(newline) is None): raise ValueError( f"Got an invalid value for default_newline: {repr(newline)}") indent = self.default_indent if not isinstance(indent, AutoConfig) and _INDENT_RE.fullmatch(indent) is None: raise ValueError( f"Got an invalid value for default_indent: {repr(indent)}")
def get_dirs(version_info): return { d.replace(typeshed.TYPESHED_PATH, "").lstrip(os.path.sep) for d in typeshed._get_typeshed_directories(version_info) } def get_stub_files(): def get_map(version_info): return typeshed._create_stub_map(version_info) map_ = typeshed._create_stub_map(TYPESHED_PYTHON3) return os.path.join(TYPESHED_PYTHON3, "functools.pyi") TYPESHED_PYTHON3 = os.path.join(typeshed.TYPESHED_PATH, "stdlib", "3") print("@", TYPESHED_PYTHON3) print("----------------------------------------") for d in get_dirs(PythonVersionInfo("3", "8")): print(d) print("----------------------------------------") print(get_stub_files().replace(os.path.expanduser("~"), "~")) print("----------------------------------------") print(jedi.Script("import string; string.capwords").usages())
import re from itertools import count from parso.utils import PythonVersionInfo from parso.utils import split_lines from parso.python.tokenize import Token from parso import parser from parso.tree import TypedLeaf, ErrorNode, ErrorLeaf version36 = PythonVersionInfo(3, 6) class TokenNamespace: _c = count() LBRACE = next(_c) RBRACE = next(_c) ENDMARKER = next(_c) COLON = next(_c) CONVERSION = next(_c) PYTHON_EXPR = next(_c) EXCLAMATION_MARK = next(_c) UNTERMINATED_STRING = next(_c) token_map = dict( (v, k) for k, v in locals().items() if not k.startswith('_')) @classmethod def generate_token_id(cls, string): if string == '{': return cls.LBRACE elif string == '}':