Thread
#ask-the-community
    a

    Andrew Achkar

    2 weeks ago
    Hi Flyte team, I noticed a strange error when attempting to run
    pylint
    on a python module contains
    TypeVar('tar.gz')
    which is used in specifying a
    FlyteFile
    . Details in 🧵
    All that’s needed to reproduce this is a file containing:
    from typing import TypeVar
    
    _ = TypeVar("tar.gz")
    Then run pylint on this file. I get a stacktrace like:
    ************* Module example
    example.py:1:0: C0114: Missing module docstring (missing-module-docstring)
    Exception on node <AssignName._ l.3 at 0x7fe8c7586580> in file '/directory/example.py'
    Traceback (most recent call last):
      File "/usr/local/venvs/test-venv/lib/python3.8/site-packages/astroid/inference_tip.py", line 37, in _inference_tip_cached
        result = _cache[func, node]
    KeyError: (<function infer_typing_typevar_or_newtype at 0x7fe8c6442670>, <Call l.3 at 0x7fe8c7586640>)
    
    During handling of the above exception, another exception occurred:
    
    Traceback (most recent call last):
      File "/usr/local/venvs/test-venv/lib/python3.8/site-packages/astroid/builder.py", line 168, in _data_build
        node, parser_module = _parse_string(data, type_comments=True)
      File "/usr/local/venvs/test-venv/lib/python3.8/site-packages/astroid/builder.py", line 454, in _parse_string
        parsed = parser_module.parse(data + "\n", type_comments=type_comments)
      File "/usr/local/venvs/test-venv/lib/python3.8/site-packages/astroid/_ast.py", line 49, in parse
        return parse_func(string)
      File "/usr/local/lib/python3.8/ast.py", line 47, in parse
        return compile(source, filename, mode, flags,
      File "<unknown>", line 10
        class tar.gz(metaclass=Meta):
                 ^
    SyntaxError: invalid syntax
    
    The above exception was the direct cause of the following exception:
    
    Traceback (most recent call last):
      File "/usr/local/venvs/test-venv/lib/python3.8/site-packages/pylint/checkers/utils.py", line 1258, in safe_infer
        value = next(infer_gen)
      File "/usr/local/venvs/test-venv/lib/python3.8/site-packages/astroid/nodes/node_ng.py", line 158, in infer
        results = list(self._explicit_inference(self, context, **kwargs))
      File "/usr/local/venvs/test-venv/lib/python3.8/site-packages/astroid/inference_tip.py", line 44, in _inference_tip_cached
        result = _cache[func, node] = list(func(*args, **kwargs))
      File "/usr/local/venvs/test-venv/lib/python3.8/site-packages/astroid/brain/brain_typing.py", line 127, in infer_typing_typevar_or_newtype
        node = extract_node(TYPING_TYPE_TEMPLATE.format(typename))
      File "/usr/local/venvs/test-venv/lib/python3.8/site-packages/astroid/builder.py", line 423, in extract_node
        tree = parse(code, module_name=module_name)
      File "/usr/local/venvs/test-venv/lib/python3.8/site-packages/astroid/builder.py", line 281, in parse
        return builder.string_build(code, modname=module_name, path=path)
      File "/usr/local/venvs/test-venv/lib/python3.8/site-packages/astroid/builder.py", line 138, in string_build
        module, builder = self._data_build(data, modname, path)
      File "/usr/local/venvs/test-venv/lib/python3.8/site-packages/astroid/builder.py", line 170, in _data_build
        raise AstroidSyntaxError(
    astroid.exceptions.AstroidSyntaxError: Parsing Python code failed:
    invalid syntax (<unknown>, line 10)
    
    The above exception was the direct cause of the following exception:
    
    Traceback (most recent call last):
      File "/usr/local/venvs/test-venv/lib/python3.8/site-packages/pylint/utils/ast_walker.py", line 90, in walk
        callback(astroid)
      File "/usr/local/venvs/test-venv/lib/python3.8/site-packages/pylint/checkers/base/name_checker/checker.py", line 411, in visit_assignname
        inferred_assign_type = utils.safe_infer(assign_type.value)
      File "/usr/local/venvs/test-venv/lib/python3.8/site-packages/pylint/checkers/utils.py", line 1262, in safe_infer
        raise AstroidError from e
    astroid.exceptions.AstroidError
    example.py:1:0: F0002: example.py: Fatal error while checking 'example.py'. Please open an issue in our bug tracker so we address this. There is a pre-filled template that you can use in '/home/vscode/.cache/pylint/pylint-crash-2022-09-12-15.txt'. (astroid-error)
    AFAICT, nothing prevents creating a TypeVar with a period in the name, however, I believe it is implied that the name should be the name of a class, which cannot contain a period.
    I think that’s what tripping up pylint.
    If I understand correctly this name is really not serving any functional purpose, but it is declaring/documenting the extension of the file. It seems a bit problematic to use TypeVar in this way, in the case of having multiple extension parts.
    Eduardo Apolinario (eapolinario)

    Eduardo Apolinario (eapolinario)

    2 weeks ago
    @Andrew Achkar, thanks for the report. I opened https://github.com/flyteorg/flyte/issues/2870 to track this issue. It should be a simple fix.