Skip to content

Complicated Python 3.6 fstrings cause astroid-error #1582

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

Closed
amal-khailtash opened this issue Jul 20, 2017 · 1 comment
Closed

Complicated Python 3.6 fstrings cause astroid-error #1582

amal-khailtash opened this issue Jul 20, 2017 · 1 comment

Comments

@amal-khailtash
Copy link

amal-khailtash commented Jul 20, 2017

Steps to reproduce

  1. run pylint on the following code:
# -*- coding: utf-8 -*-
# test.py

max_width = 10

test1 = f'{" ":{max_width+4}}'
print(f'"{test1}"')

test2 = f'[{"7":>{max_width}}:0]'
print(f'"{test2}"')

Current behavior

Pylint crashes with (astroid-error) exception.

TypeError: postinit() missing 3 required positional arguments: 'bases', 'body', and 'decorators'

Expected behavior

This should not cause an exception.

pylint --version output

No config file found, using default configuration
Traceback (most recent call last):
  File "/home/akhailta/work/Amal/Python/py_mem_wiz/.venv/lib/python3.6/site-packages/pylint/lint.py", line 896, in get_ast
    return MANAGER.ast_from_file(filepath, modname, source=True)
  File "/home/akhailta/work/Amal/Python/py_mem_wiz/.venv/lib/python3.6/site-packages/astroid/manager.py", line 80, in ast_from_file
    return AstroidBuilder(self).file_build(filepath, modname)
  File "/home/akhailta/work/Amal/Python/py_mem_wiz/.venv/lib/python3.6/site-packages/astroid/builder.py", line 152, in file_build
    return self._post_build(module, encoding)
  File "/home/akhailta/work/Amal/Python/py_mem_wiz/.venv/lib/python3.6/site-packages/astroid/builder.py", line 176, in _post_build
    module = self._manager.visit_transforms(module)
  File "/home/akhailta/work/Amal/Python/py_mem_wiz/.venv/lib/python3.6/site-packages/astroid/manager.py", line 62, in visit_transforms
    return self._transform.visit(node)
  File "/home/akhailta/work/Amal/Python/py_mem_wiz/.venv/lib/python3.6/site-packages/astroid/transforms.py", line 83, in visit
    module.body = [self._visit(child) for child in module.body]
  File "/home/akhailta/work/Amal/Python/py_mem_wiz/.venv/lib/python3.6/site-packages/astroid/transforms.py", line 83, in <listcomp>
    module.body = [self._visit(child) for child in module.body]
  File "/home/akhailta/work/Amal/Python/py_mem_wiz/.venv/lib/python3.6/site-packages/astroid/transforms.py", line 51, in _visit
    visited = self._visit_generic(value)
  File "/home/akhailta/work/Amal/Python/py_mem_wiz/.venv/lib/python3.6/site-packages/astroid/transforms.py", line 61, in _visit_generic
    return self._visit(node)
  File "/home/akhailta/work/Amal/Python/py_mem_wiz/.venv/lib/python3.6/site-packages/astroid/transforms.py", line 51, in _visit
    visited = self._visit_generic(value)
  File "/home/akhailta/work/Amal/Python/py_mem_wiz/.venv/lib/python3.6/site-packages/astroid/transforms.py", line 57, in _visit_generic
    return [self._visit_generic(child) for child in node]
  File "/home/akhailta/work/Amal/Python/py_mem_wiz/.venv/lib/python3.6/site-packages/astroid/transforms.py", line 57, in <listcomp>
    return [self._visit_generic(child) for child in node]
  File "/home/akhailta/work/Amal/Python/py_mem_wiz/.venv/lib/python3.6/site-packages/astroid/transforms.py", line 61, in _visit_generic
    return self._visit(node)
  File "/home/akhailta/work/Amal/Python/py_mem_wiz/.venv/lib/python3.6/site-packages/astroid/transforms.py", line 53, in _visit
    return self._transform(node)
  File "/home/akhailta/work/Amal/Python/py_mem_wiz/.venv/lib/python3.6/site-packages/astroid/transforms.py", line 36, in _transform
    ret = transform_func(node)
  File "/home/akhailta/work/Amal/Python/py_mem_wiz/.venv/lib/python3.6/site-packages/astroid/brain/brain_fstrings.py", line 46, in _transform_formatted_value
    parent=new_node
  File "/home/akhailta/work/Amal/Python/py_mem_wiz/.venv/lib/python3.6/site-packages/astroid/brain/brain_fstrings.py", line 31, in _clone_node_with_lineno
    new_node.postinit(**postinit_params)
TypeError: postinit() missing 3 required positional arguments: 'bases', 'body', and 'decorators'
************* Module test
F:  1, 0: <class 'TypeError'>: postinit() missing 3 required positional arguments: 'bases', 'body', and 'decorators' (astroid-error)
@yermulnik
Copy link

yermulnik commented Aug 10, 2017

I've got all the same issue with a simple code like this:

WIDTH_1ST_FIELD = 10
WIDTH_2ND_FIELD = 10

print(f'{"Key:":{WIDTH_1ST_FIELD}} {"value":{WIDTH_2ND_FIELD}}')

Waiting for astroid release. Can confirm patch works locally.

ps:

Name: astroid
Version: 1.5.3
Summary: A abstract syntax tree for Python with inference support.
Home-page: https://github.com/PyCQA/astroid
Author: Python Code Quality Authority
Author-email: [email protected]
License: LGPL
Location: /usr/local/lib/python3.6/site-packages
Requires: wrapt, lazy-object-proxy, six
Name: pylint
Version: 1.7.2
Summary: python code static checker
Home-page: https://github.com/PyCQA/pylint
Author: Python Code Quality Authority
Author-email: [email protected]
License: GPL
Location: /usr/local/lib/python3.6/site-packages
Requires: mccabe, six, isort, astroid

clrpackages pushed a commit to clearlinux-pkgs/astroid that referenced this issue Dec 20, 2017
….6.0

Ashley Whetter (1):
      Public facing node documentation

Bryce Guinta (1):
      Add transform for attr library to fix unsupported-assignment-operation false positives

Claudiu Popa (40):
      Don't crash when getting the string representation of BadUnaryOperationMessage
      Don't raise DuplicateBaseError when classes at different locations are used
      The func form of namedtuples with keywords is now understood
      Dunder class at method level is now inferred as the class of the method
      Fix indentation
      Enums created with functional syntax are now iterable. Close pylint-dev/pylint#1546
      Enums created with functional syntax are now iterable. Close pylint-dev/pylint#992
      Enum's functional form know about __members__
      Fix reconstruction of nodes for FormattedValue. Close pylint-dev/pylint#1582
      Ignore the test on <Python3.6
      namedtuple._replace expects the actual attributes to be replaced
      Disable stop-iteration-return until we'll drop support for python 2
      The result of using object.__new__ as class decorator is correctly inferred as instance
      Support AnnAssign in Enum bodies. Close #442
      Add brain tips for UUID.int
      Skip Uninferable inferred objects when inferring a Dict
      Check for both args and keyword arguments when extracting namedtuple's params. Close #450
      Remove print statement
      Ignore directories found in blacklist
      __package__ is accessible in every module. Close pylint-dev/pylint#1693
      Fix lint warnings
      lint the current directory, not the installed one
      Fix the remaining lint errors
      Run the local tests, not the installed ones, and strip the local path for coveralls
      Add ChangeLog entry
      Remove most of the copyright notices, since this file was written completely by @hippo91
      Add ChangeLog entries for @hippo91 changes
      astroid's master is 1.6
      Add pypy support for Python 3.3 in tox
      Revert "Add pypy support for Python 3.3 in tox"
      Remove file_stream since it was slated for removal for 1.6
      Fix lint
      When verifying duplicates classes in MRO, ignore on-the-fly generated classes
      Make Unknown a rhs assignable node
      Make attr.ib attributes instances of Unknown, not of Attribute
      Only mock attr.ib attributes
      Remove unreachable code
      Filter non-inferables nodes when inferring binary operations
      Add new release instructions as for pylint
      Add the release date

Hugo (4):
      Update classifiers (#453)
      Mark failing test as expected failure (#455)
      Drop support for EOL Python 3.3
      Update version comparisons after review

Michał Masłowski (1):
      Catch _NonDeducibleTypeHierarchy in inference._infer_augassign (#443)

hippo91 (8):
      Expose more objects in numpy brain tip
      Introduction of numpy.core.umath functions signatures inside numpy brain + add of a dedicated unit test
      Introduction of numpy.random.mtrand functions signatures inside numpy brain + add of a dedicated unit test
      Add of a class that wrapps the call to unittest.subTest method to handle different versions of python
      Add of encoding utf-8 declaration
      Deletion of old numpy test (replaced by a dedicated class)
      Add of copyright and simplification of the mock to try to pass python3.3 CI
      Add of decorator to skip the tests if numy module is not present

ioanatia (1):
      Fix finder for namespace packages (#440)

mathieui (1):
      Add brain_curses.py for curses attributes defined at runtime (#456)

Łukasz Rogalski (1):
      Improve understanding of collections.deque (#441)

2017-12-15 -- 1.6.0

   * When verifying duplicates classes in MRO, ignore on-the-fly generated classes

     Close pylint-dev/pylint#1706

   * Add brain tip for attrs library to prevent unsupported-assignment-operation false positives

	 Close pylint-dev/pylint#1698

   * file_stream was removed, since it was deprecated for three releases

     Instead one should use the .stream() method.

   * Vast improvements to numpy support

(NEWS truncated at 15 lines)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants