Hello community,
here is the log from the commit of package python-yapf for openSUSE:Factory checked in at 2019-07-22 17:19:12
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Comparing /work/SRC/openSUSE:Factory/python-yapf (Old)
and /work/SRC/openSUSE:Factory/.python-yapf.new.4126 (New)
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Package is "python-yapf"
Mon Jul 22 17:19:12 2019 rev:7 rq:717549 version:0.28.0
Changes:
--------
--- /work/SRC/openSUSE:Factory/python-yapf/python-yapf.changes 2019-04-14 12:22:09.899742619 +0200
+++ /work/SRC/openSUSE:Factory/.python-yapf.new.4126/python-yapf.changes 2019-07-22 17:19:13.677918456 +0200
@@ -1,0 +2,6 @@
+Mon Jul 22 11:28:10 UTC 2019 - Tomáš Chvátal
+
+- Update to 0.28.0:
+ * Bugfix release, see CHANGELOG
+
+-------------------------------------------------------------------
Old:
----
yapf-0.27.0.tar.gz
New:
----
yapf-0.28.0.tar.gz
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Other differences:
------------------
++++++ python-yapf.spec ++++++
--- /var/tmp/diff_new_pack.JIL289/_old 2019-07-22 17:19:14.933917455 +0200
+++ /var/tmp/diff_new_pack.JIL289/_new 2019-07-22 17:19:14.937917453 +0200
@@ -18,7 +18,7 @@
%{?!python_module:%define python_module() python-%{**} python3-%{**}}
Name: python-yapf
-Version: 0.27.0
+Version: 0.28.0
Release: 0
Summary: A formatter for Python code
License: Apache-2.0
@@ -61,7 +61,7 @@
%python_expand rm -r %{buildroot}%{$python_sitelib}/yapftests
%check
-%python_expand nosetests-%{$python_bin_suffix}
+%python_expand nosetests-%{$python_bin_suffix} -v
%post
%python_install_alternative yapf
++++++ yapf-0.27.0.tar.gz -> yapf-0.28.0.tar.gz ++++++
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/yapf-0.27.0/CHANGELOG new/yapf-0.28.0/CHANGELOG
--- old/yapf-0.27.0/CHANGELOG 2019-04-07 12:43:54.000000000 +0200
+++ new/yapf-0.28.0/CHANGELOG 2019-07-12 07:09:06.000000000 +0200
@@ -2,6 +2,27 @@
# All notable changes to this project will be documented in this file.
# This project adheres to [Semantic Versioning](http://semver.org/).
+## [0.28.0] 2019-07-11
+### Added
+- New knob `SPLIT_ALL_TOP_LEVEL_COMMA_SEPARATED_VALUES` is a variation on
+ `SPLIT_ALL_COMMA_SEPARATED_VALUES` in which, if a subexpression with a comma
+ fits in its starting line, then the subexpression is not split (thus avoiding
+ unnecessary splits).
+### Changed
+- Set `INDENT_DICTIONARY_VALUE` for Google style.
+### Fixed
+- `BLANK_LINE_BEFORE_NESTED_CLASS_OR_DEF=False` wasn't honored because the
+ number of newlines was erroneously calculated beforehand.
+- Lambda expressions shouldn't have an increased split penalty applied to the
+ 'lambda' keyword. This prevents them from being properly formatted when they're
+ arguments to functions.
+- A comment with continuation markers (??) shouldn't mess with the lineno count.
+- Only emit unformatted if the "disable long line" is at the end of the line.
+ Otherwise we could mess up formatting for containers which have them
+ interspersed with code.
+- Fix a potential race condition by using the correct style for opening a file
+ which may not exist.
+
## [0.27.0] 2019-04-07
### Added
- `SPLIT_BEFORE_ARITHMETIC_OPERATOR` splits before an arithmetic operator when
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/yapf-0.27.0/CONTRIBUTORS new/yapf-0.28.0/CONTRIBUTORS
--- old/yapf-0.27.0/CONTRIBUTORS 2017-04-21 07:48:44.000000000 +0200
+++ new/yapf-0.28.0/CONTRIBUTORS 2019-07-02 00:17:17.000000000 +0200
@@ -13,3 +13,4 @@
Eli Bendersky
Sam Clegg
Łukasz Langa
+Oleg Butuzov
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/yapf-0.27.0/PKG-INFO new/yapf-0.28.0/PKG-INFO
--- old/yapf-0.27.0/PKG-INFO 2019-04-07 12:45:51.000000000 +0200
+++ new/yapf-0.28.0/PKG-INFO 2019-07-12 07:09:56.000000000 +0200
@@ -1,10 +1,11 @@
-Metadata-Version: 1.1
+Metadata-Version: 1.2
Name: yapf
-Version: 0.27.0
+Version: 0.28.0
Summary: A formatter for Python code.
Home-page: UNKNOWN
-Author: Bill Wendling
-Author-email: morbo@google.com
+Author: Google Inc.
+Maintainer: Bill Wendling
+Maintainer-email: morbo@google.com
License: Apache License, Version 2.0
Description: ====
YAPF
@@ -31,14 +32,15 @@
For instance, code that conforms to the PEP 8 guidelines may not be
reformatted. But it doesn't mean that the code looks good.
- YAPF takes a different approach. It's based off of 'clang-format', developed by
- Daniel Jasper. In essence, the algorithm takes the code and reformats it to the
- best formatting that conforms to the style guide, even if the original code
- didn't violate the style guide. The idea is also similar to the 'gofmt' tool for
- the Go programming language: end all holy wars about formatting - if the whole
- codebase of a project is simply piped through YAPF whenever modifications are
- made, the style remains consistent throughout the project and there's no point
- arguing about style in every code review.
+ YAPF takes a different approach. It's based off of `'clang-format' <https://cl
+ ang.llvm.org/docs/ClangFormat.html>`_, developed by Daniel Jasper. In essence,
+ the algorithm takes the code and reformats it to the best formatting that
+ conforms to the style guide, even if the original code didn't violate the
+ style guide. The idea is also similar to the `'gofmt' <https://golang.org/cmd/
+ gofmt/>`_ tool for the Go programming language: end all holy wars about
+ formatting - if the whole codebase of a project is simply piped through YAPF
+ whenever modifications are made, the style remains consistent throughout the
+ project and there's no point arguing about style in every code review.
The ultimate goal is that the code YAPF produces is as good as the code that a
programmer would write if they were following the style guide. It takes away
@@ -148,8 +150,8 @@
Excluding files from formatting (.yapfignore)
---------------------------------------------
- In addition to exclude patterns provided on commandline, YAPF looks for additional
- patterns specified in a file named ``.yapfignore`` located in the working directory from
+ In addition to exclude patterns provided on commandline, YAPF looks for additional
+ patterns specified in a file named ``.yapfignore`` located in the working directory from
which YAPF is invoked.
@@ -190,11 +192,12 @@
YAPF will search for the formatting style in the following manner:
1. Specified on the command line
- 2. In the `[style]` section of a `.style.yapf` file in either the current
+ 2. In the ``[style]`` section of a ``.style.yapf`` file in either the current
directory or one of its parent directories.
- 3. In the `[yapf]` section of a `setup.cfg` file in either the current
+ 3. In the ``[yapf]`` section of a ``setup.cfg`` file in either the current
directory or one of its parent directories.
- 4. In the `~/.config/yapf/style` file in your home directory.
+ 4. In the ``[style]`` section of a ``~/.config/yapf/style`` file in your home
+ directory.
If none of those files are found, the default style is used (PEP8).
@@ -304,7 +307,7 @@
>>> FormatFile("foo.py")
('a == b\n', 'utf-8')
- The ``in-place`` argument saves the reformatted code back to the file:
+ The ``in_place`` argument saves the reformatted code back to the file:
.. code-block:: python
@@ -423,13 +426,14 @@
``CONTINUATION_ALIGN_STYLE``
The style for continuation alignment. Possible values are:
- - SPACE: Use spaces for continuation alignment. This is default behavior.
- - FIXED: Use fixed number (CONTINUATION_INDENT_WIDTH) of columns
+ - ``SPACE``: Use spaces for continuation alignment. This is default
+ behavior.
+ - ``FIXED``: Use fixed number (CONTINUATION_INDENT_WIDTH) of columns
(ie: CONTINUATION_INDENT_WIDTH/INDENT_WIDTH tabs) for continuation
alignment.
- - VALIGN-RIGHT: Vertically align continuation lines with indent characters.
- Slightly right (one more indent character) if cannot vertically align
- continuation lines with indent characters.
+ - ``VALIGN-RIGHT``: Vertically align continuation lines with indent
+ characters. Slightly right (one more indent character) if cannot
+ vertically align continuation lines with indent characters.
For options ``FIXED``, and ``VALIGN-RIGHT`` are only available when
``USE_TABS`` is enabled.
@@ -503,7 +507,7 @@
1 + 2 * 3 - 4 / 5
- will be formatted as follows when configured with ``*,/``:
+ will be formatted as follows when configured with ``*``, ``/``:
.. code-block:: python
@@ -523,42 +527,42 @@
alignment column values; trailing comments within a block will
be aligned to the first column value that is greater than the maximum
line length within the block). For example:
-
- With spaces_before_comment=5:
-
+
+ With ``spaces_before_comment=5``:
+
.. code-block:: python
-
+
1 + 1 # Adding values
-
+
will be formatted as:
-
+
.. code-block:: python
-
+
1 + 1 # Adding values <-- 5 spaces between the end of the statement and comment
-
- With spaces_before_comment=15, 20:
-
+
+ With ``spaces_before_comment=15, 20``:
+
.. code-block:: python
-
+
1 + 1 # Adding values
two + two # More adding
-
+
longer_statement # This is a longer statement
short # This is a shorter statement
-
+
a_very_long_statement_that_extends_beyond_the_final_column # Comment
short # This is a shorter statement
-
+
will be formatted as:
-
+
.. code-block:: python
-
+
1 + 1 # Adding values <-- end of line comments in block aligned to col 15
two + two # More adding
-
+
longer_statement # This is a longer statement <-- end of line comments in block aligned to col 20
short # This is a shorter statement
-
+
a_very_long_statement_that_extends_beyond_the_final_column # Comment <-- the end of line comments are aligned based on the line length
short # This is a shorter statement
@@ -569,19 +573,42 @@
Split before arguments if the argument list is terminated by a comma.
``SPLIT_ALL_COMMA_SEPARATED_VALUES``
- If a comma separated list (dict, list, tuple, or function def) is on a
- line that is too long, split such that all elements are on a single line.
+ If a comma separated list (``dict``, ``list``, ``tuple``, or function
+ ``def``) is on a line that is too long, split such that all elements
+ are on a single line.
+
+ ``SPLIT_ALL_TOP_LEVEL_COMMA_SEPARATED_VALUES``
+ Variation on ``SPLIT_ALL_COMMA_SEPARATED_VALUES`` in which, if a
+ subexpression with a comma fits in its starting line, then the
+ subexpression is not split. This avoids splits like the one for
+ ``b`` in this code:
+
+ .. code-block:: python
+
+ abcdef(
+ aReallyLongThing: int,
+ b: [Int,
+ Int])
+
+ With the new knob this is split as:
+
+ .. code-block:: python
+
+ abcdef(
+ aReallyLongThing: int,
+ b: [Int, Int])
``SPLIT_BEFORE_BITWISE_OPERATOR``
- Set to True to prefer splitting before '&', '|' or '^' rather than after.
+ Set to ``True`` to prefer splitting before ``&``, ``|`` or ``^`` rather
+ than after.
``SPLIT_BEFORE_ARITHMETIC_OPERATOR``
- Set to True to prefer splitting before '+', '-', '*', '/', '//', or '@'
- rather than after.
+ Set to ``True`` to prefer splitting before ``+``, ``-``, ``*``, ``/``, ``//``,
+ or ``@`` rather than after.
``SPLIT_BEFORE_CLOSING_BRACKET``
- Split before the closing bracket if a list or dict literal doesn't fit on
- a single line.
+ Split before the closing bracket if a ``list`` or ``dict`` literal doesn't
+ fit on a single line.
``SPLIT_BEFORE_DICT_SET_GENERATOR``
Split before a dictionary or set generator (comp_for). For example, note
@@ -595,7 +622,7 @@
}
``SPLIT_BEFORE_DOT``
- Split before the '.' if we need to split a longer expression:
+ Split before the ``.`` if we need to split a longer expression:
.. code-block:: python
@@ -625,8 +652,8 @@
``SPLIT_COMPLEX_COMPREHENSION``
For list comprehensions and generator expressions with multiple clauses
- (e.g multiple "for" calls, "if" filter expressions) and which need to be
- reflowed, split each clause onto its own line. For example:
+ (e.g multiple ``for`` calls, ``if`` filter expressions) and which need to
+ be reflowed, split each clause onto its own line. For example:
.. code-block:: python
@@ -759,8 +786,8 @@
-----------------------------------------
YAPF tries very hard to be fully PEP 8 compliant. However, it is paramount
- to not risk altering the semantics of your code. Thus, YAPF tries to be as
- safe as possible and does not change the token stream
+ to not risk altering the semantics of your code. Thus, YAPF tries to be as
+ safe as possible and does not change the token stream
(e.g., by adding parenthesis).
All these cases however, can be easily fixed manually. For instance,
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/yapf-0.27.0/README.rst new/yapf-0.28.0/README.rst
--- old/yapf-0.27.0/README.rst 2019-03-24 08:56:40.000000000 +0100
+++ new/yapf-0.28.0/README.rst 2019-06-21 20:33:09.000000000 +0200
@@ -23,14 +23,15 @@
For instance, code that conforms to the PEP 8 guidelines may not be
reformatted. But it doesn't mean that the code looks good.
-YAPF takes a different approach. It's based off of 'clang-format', developed by
-Daniel Jasper. In essence, the algorithm takes the code and reformats it to the
-best formatting that conforms to the style guide, even if the original code
-didn't violate the style guide. The idea is also similar to the 'gofmt' tool for
-the Go programming language: end all holy wars about formatting - if the whole
-codebase of a project is simply piped through YAPF whenever modifications are
-made, the style remains consistent throughout the project and there's no point
-arguing about style in every code review.
+YAPF takes a different approach. It's based off of `'clang-format' <https://cl
+ang.llvm.org/docs/ClangFormat.html>`_, developed by Daniel Jasper. In essence,
+the algorithm takes the code and reformats it to the best formatting that
+conforms to the style guide, even if the original code didn't violate the
+style guide. The idea is also similar to the `'gofmt' <https://golang.org/cmd/
+gofmt/>`_ tool for the Go programming language: end all holy wars about
+formatting - if the whole codebase of a project is simply piped through YAPF
+whenever modifications are made, the style remains consistent throughout the
+project and there's no point arguing about style in every code review.
The ultimate goal is that the code YAPF produces is as good as the code that a
programmer would write if they were following the style guide. It takes away
@@ -140,8 +141,8 @@
Excluding files from formatting (.yapfignore)
---------------------------------------------
-In addition to exclude patterns provided on commandline, YAPF looks for additional
-patterns specified in a file named ``.yapfignore`` located in the working directory from
+In addition to exclude patterns provided on commandline, YAPF looks for additional
+patterns specified in a file named ``.yapfignore`` located in the working directory from
which YAPF is invoked.
@@ -182,11 +183,12 @@
YAPF will search for the formatting style in the following manner:
1. Specified on the command line
-2. In the `[style]` section of a `.style.yapf` file in either the current
+2. In the ``[style]`` section of a ``.style.yapf`` file in either the current
directory or one of its parent directories.
-3. In the `[yapf]` section of a `setup.cfg` file in either the current
+3. In the ``[yapf]`` section of a ``setup.cfg`` file in either the current
directory or one of its parent directories.
-4. In the `~/.config/yapf/style` file in your home directory.
+4. In the ``[style]`` section of a ``~/.config/yapf/style`` file in your home
+ directory.
If none of those files are found, the default style is used (PEP8).
@@ -296,7 +298,7 @@
>>> FormatFile("foo.py")
('a == b\n', 'utf-8')
-The ``in-place`` argument saves the reformatted code back to the file:
+The ``in_place`` argument saves the reformatted code back to the file:
.. code-block:: python
@@ -415,13 +417,14 @@
``CONTINUATION_ALIGN_STYLE``
The style for continuation alignment. Possible values are:
- - SPACE: Use spaces for continuation alignment. This is default behavior.
- - FIXED: Use fixed number (CONTINUATION_INDENT_WIDTH) of columns
+ - ``SPACE``: Use spaces for continuation alignment. This is default
+ behavior.
+ - ``FIXED``: Use fixed number (CONTINUATION_INDENT_WIDTH) of columns
(ie: CONTINUATION_INDENT_WIDTH/INDENT_WIDTH tabs) for continuation
alignment.
- - VALIGN-RIGHT: Vertically align continuation lines with indent characters.
- Slightly right (one more indent character) if cannot vertically align
- continuation lines with indent characters.
+ - ``VALIGN-RIGHT``: Vertically align continuation lines with indent
+ characters. Slightly right (one more indent character) if cannot
+ vertically align continuation lines with indent characters.
For options ``FIXED``, and ``VALIGN-RIGHT`` are only available when
``USE_TABS`` is enabled.
@@ -495,7 +498,7 @@
1 + 2 * 3 - 4 / 5
- will be formatted as follows when configured with ``*,/``:
+ will be formatted as follows when configured with ``*``, ``/``:
.. code-block:: python
@@ -515,42 +518,42 @@
alignment column values; trailing comments within a block will
be aligned to the first column value that is greater than the maximum
line length within the block). For example:
-
- With spaces_before_comment=5:
-
+
+ With ``spaces_before_comment=5``:
+
.. code-block:: python
-
+
1 + 1 # Adding values
-
+
will be formatted as:
-
+
.. code-block:: python
-
+
1 + 1 # Adding values <-- 5 spaces between the end of the statement and comment
-
- With spaces_before_comment=15, 20:
-
+
+ With ``spaces_before_comment=15, 20``:
+
.. code-block:: python
-
+
1 + 1 # Adding values
two + two # More adding
-
+
longer_statement # This is a longer statement
short # This is a shorter statement
-
+
a_very_long_statement_that_extends_beyond_the_final_column # Comment
short # This is a shorter statement
-
+
will be formatted as:
-
+
.. code-block:: python
-
+
1 + 1 # Adding values <-- end of line comments in block aligned to col 15
two + two # More adding
-
+
longer_statement # This is a longer statement <-- end of line comments in block aligned to col 20
short # This is a shorter statement
-
+
a_very_long_statement_that_extends_beyond_the_final_column # Comment <-- the end of line comments are aligned based on the line length
short # This is a shorter statement
@@ -561,19 +564,42 @@
Split before arguments if the argument list is terminated by a comma.
``SPLIT_ALL_COMMA_SEPARATED_VALUES``
- If a comma separated list (dict, list, tuple, or function def) is on a
- line that is too long, split such that all elements are on a single line.
+ If a comma separated list (``dict``, ``list``, ``tuple``, or function
+ ``def``) is on a line that is too long, split such that all elements
+ are on a single line.
+
+``SPLIT_ALL_TOP_LEVEL_COMMA_SEPARATED_VALUES``
+ Variation on ``SPLIT_ALL_COMMA_SEPARATED_VALUES`` in which, if a
+ subexpression with a comma fits in its starting line, then the
+ subexpression is not split. This avoids splits like the one for
+ ``b`` in this code:
+
+ .. code-block:: python
+
+ abcdef(
+ aReallyLongThing: int,
+ b: [Int,
+ Int])
+
+ With the new knob this is split as:
+
+ .. code-block:: python
+
+ abcdef(
+ aReallyLongThing: int,
+ b: [Int, Int])
``SPLIT_BEFORE_BITWISE_OPERATOR``
- Set to True to prefer splitting before '&', '|' or '^' rather than after.
+ Set to ``True`` to prefer splitting before ``&``, ``|`` or ``^`` rather
+ than after.
``SPLIT_BEFORE_ARITHMETIC_OPERATOR``
- Set to True to prefer splitting before '+', '-', '*', '/', '//', or '@'
- rather than after.
+ Set to ``True`` to prefer splitting before ``+``, ``-``, ``*``, ``/``, ``//``,
+ or ``@`` rather than after.
``SPLIT_BEFORE_CLOSING_BRACKET``
- Split before the closing bracket if a list or dict literal doesn't fit on
- a single line.
+ Split before the closing bracket if a ``list`` or ``dict`` literal doesn't
+ fit on a single line.
``SPLIT_BEFORE_DICT_SET_GENERATOR``
Split before a dictionary or set generator (comp_for). For example, note
@@ -587,7 +613,7 @@
}
``SPLIT_BEFORE_DOT``
- Split before the '.' if we need to split a longer expression:
+ Split before the ``.`` if we need to split a longer expression:
.. code-block:: python
@@ -617,8 +643,8 @@
``SPLIT_COMPLEX_COMPREHENSION``
For list comprehensions and generator expressions with multiple clauses
- (e.g multiple "for" calls, "if" filter expressions) and which need to be
- reflowed, split each clause onto its own line. For example:
+ (e.g multiple ``for`` calls, ``if`` filter expressions) and which need to
+ be reflowed, split each clause onto its own line. For example:
.. code-block:: python
@@ -751,8 +777,8 @@
-----------------------------------------
YAPF tries very hard to be fully PEP 8 compliant. However, it is paramount
-to not risk altering the semantics of your code. Thus, YAPF tries to be as
-safe as possible and does not change the token stream
+to not risk altering the semantics of your code. Thus, YAPF tries to be as
+safe as possible and does not change the token stream
(e.g., by adding parenthesis).
All these cases however, can be easily fixed manually. For instance,
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/yapf-0.27.0/setup.cfg new/yapf-0.28.0/setup.cfg
--- old/yapf-0.27.0/setup.cfg 2019-04-07 12:45:51.000000000 +0200
+++ new/yapf-0.28.0/setup.cfg 2019-07-12 07:09:56.000000000 +0200
@@ -4,5 +4,4 @@
[egg_info]
tag_build =
tag_date = 0
-tag_svn_revision = 0
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/yapf-0.27.0/yapf/__init__.py new/yapf-0.28.0/yapf/__init__.py
--- old/yapf-0.27.0/yapf/__init__.py 2019-04-07 12:43:41.000000000 +0200
+++ new/yapf-0.28.0/yapf/__init__.py 2019-07-12 07:06:36.000000000 +0200
@@ -40,7 +40,7 @@
from yapf.yapflib import style
from yapf.yapflib import yapf_api
-__version__ = '0.27.0'
+__version__ = '0.28.0'
def main(argv):
@@ -121,16 +121,16 @@
'-p',
'--parallel',
action='store_true',
- help=('Run yapf in parallel when formatting multiple files. Requires '
+ help=('run yapf in parallel when formatting multiple files. Requires '
'concurrent.futures in Python 2.X'))
parser.add_argument(
'-vv',
'--verbose',
action='store_true',
- help='Print out file names while processing')
+ help='print out file names while processing')
parser.add_argument(
- 'files', nargs='*', help='Reads from stdin when no files are specified.')
+ 'files', nargs='*', help='reads from stdin when no files are specified.')
args = parser.parse_args(argv[1:])
if args.version:
@@ -149,7 +149,7 @@
print('#', line and ' ' or '', line, sep='')
option_value = style.Get(option)
if isinstance(option_value, set) or isinstance(option_value, list):
- option_value = ', '.join(option_value)
+ option_value = ', '.join(map(str, option_value))
print(option.lower(), '=', option_value, sep='')
print()
return 0
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/yapf-0.27.0/yapf/yapflib/file_resources.py new/yapf-0.28.0/yapf/yapflib/file_resources.py
--- old/yapf-0.27.0/yapf/yapflib/file_resources.py 2019-02-09 14:56:52.000000000 +0100
+++ new/yapf-0.28.0/yapf/yapflib/file_resources.py 2019-07-02 00:17:32.000000000 +0200
@@ -86,8 +86,12 @@
# See if we have a setup.cfg file with a '[yapf]' section.
config_file = os.path.join(dirname, style.SETUP_CONFIG)
- if os.path.exists(config_file):
- with open(config_file) as fd:
+ try:
+ fd = open(config_file)
+ except IOError:
+ pass # It's okay if it's not there.
+ else:
+ with fd:
config = py3compat.ConfigParser()
config.read_file(fd)
if config.has_section('yapf'):
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/yapf-0.27.0/yapf/yapflib/format_decision_state.py new/yapf-0.28.0/yapf/yapflib/format_decision_state.py
--- old/yapf-0.27.0/yapf/yapflib/format_decision_state.py 2019-04-07 11:18:51.000000000 +0200
+++ new/yapf-0.28.0/yapf/yapflib/format_decision_state.py 2019-07-02 00:41:35.000000000 +0200
@@ -176,6 +176,19 @@
if style.Get('SPLIT_ALL_COMMA_SEPARATED_VALUES') and previous.value == ',':
return True
+ if (style.Get('SPLIT_ALL_TOP_LEVEL_COMMA_SEPARATED_VALUES') and
+ previous.value == ','):
+ # Avoid breaking in a container that fits in the current line if possible
+ opening = _GetOpeningBracket(current)
+
+ # Can't find opening bracket, behave the same way as
+ # SPLIT_ALL_COMMA_SEPARATED_VALUES
+ if not opening:
+ return True
+
+ # If the container doesn't fit in the current line, must split
+ return not self._ContainerFitsOnStartLine(opening)
+
if (self.stack[-1].split_before_closing_bracket and
current.value in '}]' and style.Get('SPLIT_BEFORE_CLOSING_BRACKET')):
# Split before the closing bracket if we can.
@@ -370,10 +383,7 @@
opening = _GetOpeningBracket(current)
if opening:
- arglist_length = (
- opening.matching_bracket.total_length - opening.total_length +
- self.stack[-1].indent)
- return arglist_length > self.column_limit
+ return not self._ContainerFitsOnStartLine(opening)
if (current.value not in '{)' and previous.value == '(' and
self._ArgumentListHasDictionaryEntry(current)):
@@ -935,6 +945,18 @@
token = token.next_token
return False
+ def _ContainerFitsOnStartLine(self, opening):
+ """Check if the container can fit on its starting line.
+
+ Arguments:
+ opening: (FormatToken) The unwrapped line we're currently processing.
+
+ Returns:
+ True if the container fits on the start line.
+ """
+ return (opening.matching_bracket.total_length - opening.total_length +
+ self.stack[-1].indent) <= self.column_limit
+
_COMPOUND_STMTS = frozenset(
{'for', 'while', 'if', 'elif', 'with', 'except', 'def', 'class'})
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/yapf-0.27.0/yapf/yapflib/reformatter.py new/yapf-0.28.0/yapf/yapflib/reformatter.py
--- old/yapf-0.27.0/yapf/yapflib/reformatter.py 2019-04-07 11:58:21.000000000 +0200
+++ new/yapf-0.28.0/yapf/yapflib/reformatter.py 2019-06-27 19:27:03.000000000 +0200
@@ -122,6 +122,7 @@
prev_tok = None
if prev_uwline is not None:
prev_tok = prev_uwline.last
+
for cur_tok in cur_uwline.tokens:
_RetainRequiredVerticalSpacingBetweenTokens(cur_tok, prev_tok, lines)
@@ -152,7 +153,7 @@
else:
cur_lineno = cur_tok.lineno
- if prev_tok.value.endswith('\\'):
+ if not prev_tok.is_comment and prev_tok.value.endswith('\\'):
prev_lineno += prev_tok.value.count('\n')
required_newlines = cur_lineno - prev_lineno
@@ -239,10 +240,7 @@
def _LineContainsPylintDisableLineTooLong(uwline):
"""Return true if there is a "pylint: disable=line-too-long" comment."""
- return any(
- re.search(r'\bpylint:\s+disable=line-too-long\b', tok.value)
- for tok in uwline.tokens
- if tok.is_comment)
+ return re.search(r'\bpylint:\s+disable=line-too-long\b', uwline.last.value)
def _LineHasContinuationMarkers(uwline):
@@ -587,11 +585,11 @@
TWO_BLANK_LINES = 3
-def _IsClassOrDef(uwline):
- if uwline.first.value in {'class', 'def'}:
+def _IsClassOrDef(tok):
+ if tok.value in {'class', 'def', '@'}:
return True
-
- return [t.value for t in uwline.tokens[:2]] == ['async', 'def']
+ return (tok.next_token and tok.value == 'async' and
+ tok.next_token.value == 'def')
def _CalculateNumberOfNewlines(first_token, indent_depth, prev_uwline,
@@ -638,6 +636,11 @@
# Separate a class or function from the module-level docstring with
# appropriate number of blank lines.
return 1 + style.Get('BLANK_LINES_AROUND_TOP_LEVEL_DEFINITION')
+ if (not style.Get('BLANK_LINE_BEFORE_NESTED_CLASS_OR_DEF') and
+ _IsClassOrDef(first_token)):
+ pytree_utils.SetNodeAnnotation(first_token.node,
+ pytree_utils.Annotation.NEWLINES, None)
+ return NO_BLANK_LINES
if _NoBlankLinesBeforeCurrentToken(prev_last_token.value, first_token,
prev_last_token):
return NO_BLANK_LINES
@@ -672,7 +675,7 @@
pytree_utils.Annotation.NEWLINES,
None)
return NO_BLANK_LINES
- elif _IsClassOrDef(prev_uwline):
+ elif _IsClassOrDef(prev_uwline.first):
if not style.Get('BLANK_LINE_BEFORE_NESTED_CLASS_OR_DEF'):
pytree_utils.SetNodeAnnotation(first_token.node,
pytree_utils.Annotation.NEWLINES, None)
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/yapf-0.27.0/yapf/yapflib/split_penalty.py new/yapf-0.28.0/yapf/yapflib/split_penalty.py
--- old/yapf-0.27.0/yapf/yapflib/split_penalty.py 2019-04-07 11:46:46.000000000 +0200
+++ new/yapf-0.28.0/yapf/yapflib/split_penalty.py 2019-07-02 00:24:02.000000000 +0200
@@ -129,9 +129,9 @@
break
if allow_multiline_lambdas:
- _SetStronglyConnected(node)
+ _SetExpressionPenalty(node, STRONGLY_CONNECTED)
else:
- _SetVeryStronglyConnected(node)
+ _SetExpressionPenalty(node, VERY_STRONGLY_CONNECTED)
def Visit_parameters(self, node): # pylint: disable=invalid-name
# parameters ::= '(' [typedargslist] ')'
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/yapf-0.27.0/yapf/yapflib/style.py new/yapf-0.28.0/yapf/yapflib/style.py
--- old/yapf-0.27.0/yapf/yapflib/style.py 2019-03-24 08:56:40.000000000 +0100
+++ new/yapf-0.28.0/yapf/yapflib/style.py 2019-05-07 00:56:23.000000000 +0200
@@ -239,6 +239,9 @@
comma."""),
SPLIT_ALL_COMMA_SEPARATED_VALUES=textwrap.dedent("""\
Split before arguments"""),
+ SPLIT_ALL_TOP_LEVEL_COMMA_SEPARATED_VALUES=textwrap.dedent("""\
+ Split before arguments, but do not split all subexpressions recursively
+ (unless needed)."""),
SPLIT_BEFORE_ARITHMETIC_OPERATOR=textwrap.dedent("""\
Set to True to prefer splitting before '+', '-', '*', '/', '//', or '@'
rather than after."""),
@@ -367,6 +370,7 @@
SPACES_BEFORE_COMMENT=2,
SPLIT_ARGUMENTS_WHEN_COMMA_TERMINATED=False,
SPLIT_ALL_COMMA_SEPARATED_VALUES=False,
+ SPLIT_ALL_TOP_LEVEL_COMMA_SEPARATED_VALUES=False,
SPLIT_BEFORE_ARITHMETIC_OPERATOR=False,
SPLIT_BEFORE_BITWISE_OPERATOR=True,
SPLIT_BEFORE_CLOSING_BRACKET=True,
@@ -396,6 +400,7 @@
style['ALIGN_CLOSING_BRACKET_WITH_VISUAL_INDENT'] = False
style['BLANK_LINE_BEFORE_NESTED_CLASS_OR_DEF'] = True
style['COLUMN_LIMIT'] = 80
+ style['INDENT_DICTIONARY_VALUE'] = True
style['INDENT_WIDTH'] = 4
style['I18N_COMMENT'] = r'#\..*'
style['I18N_FUNCTION_CALL'] = ['N_', '_']
@@ -542,6 +547,7 @@
SPACES_BEFORE_COMMENT=_IntOrIntListConverter,
SPLIT_ARGUMENTS_WHEN_COMMA_TERMINATED=_BoolConverter,
SPLIT_ALL_COMMA_SEPARATED_VALUES=_BoolConverter,
+ SPLIT_ALL_TOP_LEVEL_COMMA_SEPARATED_VALUES=_BoolConverter,
SPLIT_BEFORE_ARITHMETIC_OPERATOR=_BoolConverter,
SPLIT_BEFORE_BITWISE_OPERATOR=_BoolConverter,
SPLIT_BEFORE_CLOSING_BRACKET=_BoolConverter,
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/yapf-0.27.0/yapf.egg-info/PKG-INFO new/yapf-0.28.0/yapf.egg-info/PKG-INFO
--- old/yapf-0.27.0/yapf.egg-info/PKG-INFO 2019-04-07 12:45:51.000000000 +0200
+++ new/yapf-0.28.0/yapf.egg-info/PKG-INFO 2019-07-12 07:09:56.000000000 +0200
@@ -1,10 +1,11 @@
-Metadata-Version: 1.1
+Metadata-Version: 1.2
Name: yapf
-Version: 0.27.0
+Version: 0.28.0
Summary: A formatter for Python code.
Home-page: UNKNOWN
-Author: Bill Wendling
-Author-email: morbo@google.com
+Author: Google Inc.
+Maintainer: Bill Wendling
+Maintainer-email: morbo@google.com
License: Apache License, Version 2.0
Description: ====
YAPF
@@ -31,14 +32,15 @@
For instance, code that conforms to the PEP 8 guidelines may not be
reformatted. But it doesn't mean that the code looks good.
- YAPF takes a different approach. It's based off of 'clang-format', developed by
- Daniel Jasper. In essence, the algorithm takes the code and reformats it to the
- best formatting that conforms to the style guide, even if the original code
- didn't violate the style guide. The idea is also similar to the 'gofmt' tool for
- the Go programming language: end all holy wars about formatting - if the whole
- codebase of a project is simply piped through YAPF whenever modifications are
- made, the style remains consistent throughout the project and there's no point
- arguing about style in every code review.
+ YAPF takes a different approach. It's based off of `'clang-format' <https://cl
+ ang.llvm.org/docs/ClangFormat.html>`_, developed by Daniel Jasper. In essence,
+ the algorithm takes the code and reformats it to the best formatting that
+ conforms to the style guide, even if the original code didn't violate the
+ style guide. The idea is also similar to the `'gofmt' <https://golang.org/cmd/
+ gofmt/>`_ tool for the Go programming language: end all holy wars about
+ formatting - if the whole codebase of a project is simply piped through YAPF
+ whenever modifications are made, the style remains consistent throughout the
+ project and there's no point arguing about style in every code review.
The ultimate goal is that the code YAPF produces is as good as the code that a
programmer would write if they were following the style guide. It takes away
@@ -148,8 +150,8 @@
Excluding files from formatting (.yapfignore)
---------------------------------------------
- In addition to exclude patterns provided on commandline, YAPF looks for additional
- patterns specified in a file named ``.yapfignore`` located in the working directory from
+ In addition to exclude patterns provided on commandline, YAPF looks for additional
+ patterns specified in a file named ``.yapfignore`` located in the working directory from
which YAPF is invoked.
@@ -190,11 +192,12 @@
YAPF will search for the formatting style in the following manner:
1. Specified on the command line
- 2. In the `[style]` section of a `.style.yapf` file in either the current
+ 2. In the ``[style]`` section of a ``.style.yapf`` file in either the current
directory or one of its parent directories.
- 3. In the `[yapf]` section of a `setup.cfg` file in either the current
+ 3. In the ``[yapf]`` section of a ``setup.cfg`` file in either the current
directory or one of its parent directories.
- 4. In the `~/.config/yapf/style` file in your home directory.
+ 4. In the ``[style]`` section of a ``~/.config/yapf/style`` file in your home
+ directory.
If none of those files are found, the default style is used (PEP8).
@@ -304,7 +307,7 @@
>>> FormatFile("foo.py")
('a == b\n', 'utf-8')
- The ``in-place`` argument saves the reformatted code back to the file:
+ The ``in_place`` argument saves the reformatted code back to the file:
.. code-block:: python
@@ -423,13 +426,14 @@
``CONTINUATION_ALIGN_STYLE``
The style for continuation alignment. Possible values are:
- - SPACE: Use spaces for continuation alignment. This is default behavior.
- - FIXED: Use fixed number (CONTINUATION_INDENT_WIDTH) of columns
+ - ``SPACE``: Use spaces for continuation alignment. This is default
+ behavior.
+ - ``FIXED``: Use fixed number (CONTINUATION_INDENT_WIDTH) of columns
(ie: CONTINUATION_INDENT_WIDTH/INDENT_WIDTH tabs) for continuation
alignment.
- - VALIGN-RIGHT: Vertically align continuation lines with indent characters.
- Slightly right (one more indent character) if cannot vertically align
- continuation lines with indent characters.
+ - ``VALIGN-RIGHT``: Vertically align continuation lines with indent
+ characters. Slightly right (one more indent character) if cannot
+ vertically align continuation lines with indent characters.
For options ``FIXED``, and ``VALIGN-RIGHT`` are only available when
``USE_TABS`` is enabled.
@@ -503,7 +507,7 @@
1 + 2 * 3 - 4 / 5
- will be formatted as follows when configured with ``*,/``:
+ will be formatted as follows when configured with ``*``, ``/``:
.. code-block:: python
@@ -523,42 +527,42 @@
alignment column values; trailing comments within a block will
be aligned to the first column value that is greater than the maximum
line length within the block). For example:
-
- With spaces_before_comment=5:
-
+
+ With ``spaces_before_comment=5``:
+
.. code-block:: python
-
+
1 + 1 # Adding values
-
+
will be formatted as:
-
+
.. code-block:: python
-
+
1 + 1 # Adding values <-- 5 spaces between the end of the statement and comment
-
- With spaces_before_comment=15, 20:
-
+
+ With ``spaces_before_comment=15, 20``:
+
.. code-block:: python
-
+
1 + 1 # Adding values
two + two # More adding
-
+
longer_statement # This is a longer statement
short # This is a shorter statement
-
+
a_very_long_statement_that_extends_beyond_the_final_column # Comment
short # This is a shorter statement
-
+
will be formatted as:
-
+
.. code-block:: python
-
+
1 + 1 # Adding values <-- end of line comments in block aligned to col 15
two + two # More adding
-
+
longer_statement # This is a longer statement <-- end of line comments in block aligned to col 20
short # This is a shorter statement
-
+
a_very_long_statement_that_extends_beyond_the_final_column # Comment <-- the end of line comments are aligned based on the line length
short # This is a shorter statement
@@ -569,19 +573,42 @@
Split before arguments if the argument list is terminated by a comma.
``SPLIT_ALL_COMMA_SEPARATED_VALUES``
- If a comma separated list (dict, list, tuple, or function def) is on a
- line that is too long, split such that all elements are on a single line.
+ If a comma separated list (``dict``, ``list``, ``tuple``, or function
+ ``def``) is on a line that is too long, split such that all elements
+ are on a single line.
+
+ ``SPLIT_ALL_TOP_LEVEL_COMMA_SEPARATED_VALUES``
+ Variation on ``SPLIT_ALL_COMMA_SEPARATED_VALUES`` in which, if a
+ subexpression with a comma fits in its starting line, then the
+ subexpression is not split. This avoids splits like the one for
+ ``b`` in this code:
+
+ .. code-block:: python
+
+ abcdef(
+ aReallyLongThing: int,
+ b: [Int,
+ Int])
+
+ With the new knob this is split as:
+
+ .. code-block:: python
+
+ abcdef(
+ aReallyLongThing: int,
+ b: [Int, Int])
``SPLIT_BEFORE_BITWISE_OPERATOR``
- Set to True to prefer splitting before '&', '|' or '^' rather than after.
+ Set to ``True`` to prefer splitting before ``&``, ``|`` or ``^`` rather
+ than after.
``SPLIT_BEFORE_ARITHMETIC_OPERATOR``
- Set to True to prefer splitting before '+', '-', '*', '/', '//', or '@'
- rather than after.
+ Set to ``True`` to prefer splitting before ``+``, ``-``, ``*``, ``/``, ``//``,
+ or ``@`` rather than after.
``SPLIT_BEFORE_CLOSING_BRACKET``
- Split before the closing bracket if a list or dict literal doesn't fit on
- a single line.
+ Split before the closing bracket if a ``list`` or ``dict`` literal doesn't
+ fit on a single line.
``SPLIT_BEFORE_DICT_SET_GENERATOR``
Split before a dictionary or set generator (comp_for). For example, note
@@ -595,7 +622,7 @@
}
``SPLIT_BEFORE_DOT``
- Split before the '.' if we need to split a longer expression:
+ Split before the ``.`` if we need to split a longer expression:
.. code-block:: python
@@ -625,8 +652,8 @@
``SPLIT_COMPLEX_COMPREHENSION``
For list comprehensions and generator expressions with multiple clauses
- (e.g multiple "for" calls, "if" filter expressions) and which need to be
- reflowed, split each clause onto its own line. For example:
+ (e.g multiple ``for`` calls, ``if`` filter expressions) and which need to
+ be reflowed, split each clause onto its own line. For example:
.. code-block:: python
@@ -759,8 +786,8 @@
-----------------------------------------
YAPF tries very hard to be fully PEP 8 compliant. However, it is paramount
- to not risk altering the semantics of your code. Thus, YAPF tries to be as
- safe as possible and does not change the token stream
+ to not risk altering the semantics of your code. Thus, YAPF tries to be as
+ safe as possible and does not change the token stream
(e.g., by adding parenthesis).
All these cases however, can be easily fixed manually. For instance,
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/yapf-0.27.0/yapftests/reformatter_basic_test.py new/yapf-0.28.0/yapftests/reformatter_basic_test.py
--- old/yapf-0.27.0/yapftests/reformatter_basic_test.py 2019-04-07 11:45:24.000000000 +0200
+++ new/yapf-0.28.0/yapftests/reformatter_basic_test.py 2019-05-07 00:56:23.000000000 +0200
@@ -43,6 +43,8 @@
"whatever": 120
}
""")
+ uwlines = yapf_test_helper.ParseAndUnwrap(unformatted_code)
+ self.assertCodeEqual(expected_formatted_code, reformatter.Reformat(uwlines))
unformatted_code = textwrap.dedent("""\
def foo(long_arg, really_long_arg, really_really_long_arg, cant_keep_all_these_args):
pass
@@ -77,6 +79,116 @@
""")
uwlines = yapf_test_helper.ParseAndUnwrap(unformatted_code)
self.assertCodeEqual(expected_formatted_code, reformatter.Reformat(uwlines))
+ # There is a test for split_all_top_level_comma_separated_values, with
+ # different expected value
+ unformatted_code = textwrap.dedent("""\
+ someLongFunction(this_is_a_very_long_parameter,
+ abc=(a, this_will_just_fit_xxxxxxx))
+ """)
+ expected_formatted_code = textwrap.dedent("""\
+ someLongFunction(
+ this_is_a_very_long_parameter,
+ abc=(a,
+ this_will_just_fit_xxxxxxx))
+ """)
+ uwlines = yapf_test_helper.ParseAndUnwrap(unformatted_code)
+ self.assertCodeEqual(expected_formatted_code, reformatter.Reformat(uwlines))
+
+ def testSplittingTopLevelAllArgs(self):
+ style.SetGlobalStyle(
+ style.CreateStyleFromConfig(
+ '{split_all_top_level_comma_separated_values: true, column_limit: 40}'
+ ))
+ # Works the same way as split_all_comma_separated_values
+ unformatted_code = textwrap.dedent("""\
+ responseDict = {"timestamp": timestamp, "someValue": value, "whatever": 120}
+ """)
+ expected_formatted_code = textwrap.dedent("""\
+ responseDict = {
+ "timestamp": timestamp,
+ "someValue": value,
+ "whatever": 120
+ }
+ """)
+ uwlines = yapf_test_helper.ParseAndUnwrap(unformatted_code)
+ self.assertCodeEqual(expected_formatted_code, reformatter.Reformat(uwlines))
+ # Works the same way as split_all_comma_separated_values
+ unformatted_code = textwrap.dedent("""\
+ def foo(long_arg, really_long_arg, really_really_long_arg, cant_keep_all_these_args):
+ pass
+ """)
+ expected_formatted_code = textwrap.dedent("""\
+ def foo(long_arg,
+ really_long_arg,
+ really_really_long_arg,
+ cant_keep_all_these_args):
+ pass
+ """)
+ uwlines = yapf_test_helper.ParseAndUnwrap(unformatted_code)
+ self.assertCodeEqual(expected_formatted_code, reformatter.Reformat(uwlines))
+ # Works the same way as split_all_comma_separated_values
+ unformatted_code = textwrap.dedent("""\
+ foo_tuple = [long_arg, really_long_arg, really_really_long_arg, cant_keep_all_these_args]
+ """)
+ expected_formatted_code = textwrap.dedent("""\
+ foo_tuple = [
+ long_arg,
+ really_long_arg,
+ really_really_long_arg,
+ cant_keep_all_these_args
+ ]
+ """)
+ uwlines = yapf_test_helper.ParseAndUnwrap(unformatted_code)
+ self.assertCodeEqual(expected_formatted_code, reformatter.Reformat(uwlines))
+ # Works the same way as split_all_comma_separated_values
+ unformatted_code = textwrap.dedent("""\
+ foo_tuple = [short, arg]
+ """)
+ expected_formatted_code = textwrap.dedent("""\
+ foo_tuple = [short, arg]
+ """)
+ uwlines = yapf_test_helper.ParseAndUnwrap(unformatted_code)
+ self.assertCodeEqual(expected_formatted_code, reformatter.Reformat(uwlines))
+ # There is a test for split_all_comma_separated_values, with different
+ # expected value
+ unformatted_code = textwrap.dedent("""\
+ someLongFunction(this_is_a_very_long_parameter,
+ abc=(a, this_will_just_fit_xxxxxxx))
+ """)
+ expected_formatted_code = textwrap.dedent("""\
+ someLongFunction(
+ this_is_a_very_long_parameter,
+ abc=(a, this_will_just_fit_xxxxxxx))
+ """)
+ uwlines = yapf_test_helper.ParseAndUnwrap(unformatted_code)
+ actual_formatted_code = reformatter.Reformat(uwlines)
+ self.assertEqual(40, len(actual_formatted_code.splitlines()[-1]))
+ self.assertCodeEqual(expected_formatted_code, actual_formatted_code)
+
+ unformatted_code = textwrap.dedent("""\
+ someLongFunction(this_is_a_very_long_parameter,
+ abc=(a, this_will_not_fit_xxxxxxxxx))
+ """)
+ expected_formatted_code = textwrap.dedent("""\
+ someLongFunction(
+ this_is_a_very_long_parameter,
+ abc=(a,
+ this_will_not_fit_xxxxxxxxx))
+ """)
+ uwlines = yapf_test_helper.ParseAndUnwrap(unformatted_code)
+ self.assertCodeEqual(expected_formatted_code, reformatter.Reformat(uwlines))
+
+ # Exercise the case where there's no opening bracket (for a, b)
+ unformatted_code = textwrap.dedent("""\
+ a, b = f(
+ a_very_long_parameter, yet_another_one, and_another)
+ """)
+ expected_formatted_code = textwrap.dedent("""\
+ a, b = f(
+ a_very_long_parameter, yet_another_one, and_another)
+ """)
+ uwlines = yapf_test_helper.ParseAndUnwrap(unformatted_code)
+ self.assertCodeEqual(expected_formatted_code, reformatter.Reformat(uwlines))
def testSimpleFunctionsWithTrailingComments(self):
unformatted_code = textwrap.dedent("""\
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/yapf-0.27.0/yapftests/reformatter_buganizer_test.py new/yapf-0.28.0/yapftests/reformatter_buganizer_test.py
--- old/yapf-0.27.0/yapftests/reformatter_buganizer_test.py 2019-04-07 12:30:31.000000000 +0200
+++ new/yapf-0.28.0/yapftests/reformatter_buganizer_test.py 2019-06-27 19:29:00.000000000 +0200
@@ -28,6 +28,30 @@
def setUpClass(cls):
style.SetGlobalStyle(style.CreateChromiumStyle())
+ def testB132886019(self):
+ code = """\
+X = {
+ 'some_dict_key':
+ frozenset([
+ # pylint: disable=line-too-long
+ '//this/path/is/really/too/long/for/this/line/and/probably/should/be/split',
+ ]),
+}
+"""
+ uwlines = yapf_test_helper.ParseAndUnwrap(code)
+ self.assertCodeEqual(code, reformatter.Reformat(uwlines))
+
+ def testB26521719(self):
+ code = """\
+class _():
+
+ def _(self):
+ self.stubs.Set(some_type_of_arg, 'ThisIsAStringArgument',
+ lambda *unused_args, **unused_kwargs: fake_resolver)
+"""
+ uwlines = yapf_test_helper.ParseAndUnwrap(code)
+ self.assertCodeEqual(code, reformatter.Reformat(uwlines))
+
def testB122541552(self):
code = """\
# pylint: disable=g-explicit-bool-comparison,singleton-comparison
@@ -271,6 +295,33 @@
"""
uwlines = yapf_test_helper.ParseAndUnwrap(code)
self.assertCodeEqual(code, reformatter.Reformat(uwlines))
+
+ def testB120771563(self):
+ code = """\
+class A:
+
+ def b():
+ d = {
+ "123456": [{
+ "12": "aa"
+ }, {
+ "12": "bb"
+ }, {
+ "12": "cc",
+ "1234567890": {
+ "1234567": [{
+ "12": "dd",
+ "12345": "text 1"
+ }, {
+ "12": "ee",
+ "12345": "text 2"
+ }]
+ }
+ }]
+ }
+"""
+ uwlines = yapf_test_helper.ParseAndUnwrap(code)
+ self.assertCodeEqual(code, reformatter.Reformat(uwlines))
def testB79462249(self):
code = """\
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/yapf-0.27.0/yapftests/reformatter_pep8_test.py new/yapf-0.28.0/yapftests/reformatter_pep8_test.py
--- old/yapf-0.27.0/yapftests/reformatter_pep8_test.py 2019-04-07 11:44:33.000000000 +0200
+++ new/yapf-0.28.0/yapftests/reformatter_pep8_test.py 2019-04-09 22:17:13.000000000 +0200
@@ -491,6 +491,47 @@
uwlines = yapf_test_helper.ParseAndUnwrap(unformatted_code)
self.assertCodeEqual(expected_code, reformatter.Reformat(uwlines))
+ def testNoBlankLineBeforeNestedFuncOrClass(self):
+ try:
+ style.SetGlobalStyle(
+ style.CreateStyleFromConfig(
+ '{based_on_style: pep8, '
+ 'blank_line_before_nested_class_or_def: false}'))
+
+ unformatted_code = '''\
+def normal_function():
+ """Return the nested function."""
+
+ def nested_function():
+ """Do nothing just nest within."""
+
+ @nested(klass)
+ class nested_class():
+ pass
+
+ pass
+
+ return nested_function
+'''
+ expected_formatted_code = '''\
+def normal_function():
+ """Return the nested function."""
+ def nested_function():
+ """Do nothing just nest within."""
+ @nested(klass)
+ class nested_class():
+ pass
+
+ pass
+
+ return nested_function
+'''
+ uwlines = yapf_test_helper.ParseAndUnwrap(unformatted_code)
+ self.assertCodeEqual(expected_formatted_code,
+ reformatter.Reformat(uwlines))
+ finally:
+ style.SetGlobalStyle(style.CreatePEP8Style())
+
if __name__ == '__main__':
unittest.main()
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/yapf-0.27.0/yapftests/split_penalty_test.py new/yapf-0.28.0/yapftests/split_penalty_test.py
--- old/yapf-0.27.0/yapftests/split_penalty_test.py 2018-11-28 10:03:30.000000000 +0100
+++ new/yapf-0.28.0/yapftests/split_penalty_test.py 2019-06-21 20:42:09.000000000 +0200
@@ -139,7 +139,7 @@
""")
tree = self._ParseAndComputePenalties(code)
self._CheckPenalties(tree, [
- ('lambda', VERY_STRONGLY_CONNECTED),
+ ('lambda', None),
('a', VERY_STRONGLY_CONNECTED),
(',', VERY_STRONGLY_CONNECTED),
('b', VERY_STRONGLY_CONNECTED),
@@ -180,7 +180,7 @@
(',', None),
('y', None),
('(', UNBREAKABLE),
- ('lambda', VERY_STRONGLY_CONNECTED),
+ ('lambda', STRONGLY_CONNECTED),
('a', VERY_STRONGLY_CONNECTED),
(':', VERY_STRONGLY_CONNECTED),
('23', VERY_STRONGLY_CONNECTED),
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/yapf-0.27.0/yapftests/yapf_test.py new/yapf-0.28.0/yapftests/yapf_test.py
--- old/yapf-0.27.0/yapftests/yapf_test.py 2019-04-07 12:38:27.000000000 +0200
+++ new/yapf-0.28.0/yapftests/yapf_test.py 2019-06-21 22:07:33.000000000 +0200
@@ -840,6 +840,28 @@
self.assertYapfReformats(
unformatted_code, unformatted_code, extra_options=['--lines', '2-2'])
+ def testVerticalSpacingWithCommentWithContinuationMarkers(self):
+ unformatted_code = """\
+# \\
+# \\
+# \\
+
+x = {
+}
+"""
+ expected_formatted_code = """\
+# \\
+# \\
+# \\
+
+x = {
+}
+"""
+ self.assertYapfReformats(
+ unformatted_code,
+ expected_formatted_code,
+ extra_options=['--lines', '1-1'])
+
def testRetainingSemicolonsWhenSpecifyingLines(self):
unformatted_code = textwrap.dedent("""\
a = line_to_format