Comments (4)
I believe I am also experiencing this, which ends up with a 3000+ length line for me:
@@ -749,183 +667,19 @@ class TestFileUpload:
@pytest.mark.parametrize(
("post_data", "message"),
- [
- # metadata_version errors.
- (
- {},
- "None is an invalid value for Metadata-Version. "
- "Error: This field is required. "
- "see "
- "https://packaging.python.org/specifications/core-metadata",
- ),
- (
- {"metadata_version": "-1"},
- "'-1' is an invalid value for Metadata-Version. "
- "Error: Unknown Metadata Version "
- "see "
- "https://packaging.python.org/specifications/core-metadata",
- ),
-
- # name errors.
- (
- {"metadata_version": "1.2"},
- "'' is an invalid value for Name. "
- "Error: This field is required. "
- "see "
- "https://packaging.python.org/specifications/core-metadata",
- ),
- (
- {"metadata_version": "1.2", "name": "foo-"},
- "'foo-' is an invalid value for Name. "
- "Error: Must start and end with a letter or numeral and "
- "contain only ascii numeric and '.', '_' and '-'. "
- "see "
- "https://packaging.python.org/specifications/core-metadata",
- ),
-
- # version errors.
- (
- {"metadata_version": "1.2", "name": "example"},
- "'' is an invalid value for Version. "
- "Error: This field is required. "
- "see "
- "https://packaging.python.org/specifications/core-metadata",
- ),
- (
- {
- "metadata_version": "1.2",
- "name": "example",
- "version": "dog",
- },
- "'dog' is an invalid value for Version. "
- "Error: Must start and end with a letter or numeral and "
- "contain only ascii numeric and '.', '_' and '-'. "
- "see "
- "https://packaging.python.org/specifications/core-metadata",
- ),
-
- # filetype/pyversion errors.
- (
- {
- "metadata_version": "1.2",
- "name": "example",
- "version": "1.0",
- "md5_digest": "bad",
- },
- "filetype: This field is required.",
- ),
- (
- {
- "metadata_version": "1.2",
- "name": "example",
- "version": "1.0",
- "filetype": "bdist_wat",
- },
- "Error: Python version is required for binary distribution "
- "uploads."
- ),
- (
- {
- "metadata_version": "1.2",
- "name": "example",
- "version": "1.0",
- "filetype": "bdist_wat",
- "pyversion": "1.0",
- "md5_digest": "bad",
- },
- "filetype: Unknown type of file.",
- ),
- (
- {
- "metadata_version": "1.2",
- "name": "example",
- "version": "1.0",
- "filetype": "sdist",
- "pyversion": "1.0",
- },
- "Error: The only valid Python version for a sdist is "
- "'source'."
- ),
-
- # digest errors.
- (
- {
- "metadata_version": "1.2",
- "name": "example",
- "version": "1.0",
- "filetype": "sdist",
- },
- "Error: Must include at least one message digest."
- ),
- (
- {
- "metadata_version": "1.2",
- "name": "example",
- "version": "1.0",
- "filetype": "sdist",
- "sha256_digest": "an invalid sha256 digest",
- },
- "sha256_digest: "
- "Must be a valid, hex encoded, SHA256 message digest."
- ),
-
- # summary errors
- (
- {
- "metadata_version": "1.2",
- "name": "example",
- "version": "1.0",
- "filetype": "sdist",
- "md5_digest": "a fake md5 digest",
- "summary": "A" * 513,
- },
- "'" + "A" * 513 + "' is an invalid value for Summary. "
- "Error: Field cannot be longer than 512 characters. "
- "see "
- "https://packaging.python.org/specifications/core-metadata",
- ),
- (
- {
- "metadata_version": "1.2",
- "name": "example",
- "version": "1.0",
- "filetype": "sdist",
- "md5_digest": "a fake md5 digest",
- "summary": "A\nB",
- },
- ("{!r} is an invalid value for Summary. ".format('A\nB') +
- "Error: Multiple lines are not allowed. "
- "see "
- "https://packaging.python.org/specifications/core-metadata"),
- ),
-
- # classifiers are a FieldStorage
- (
- {
- "metadata_version": "1.2",
- "name": "example",
- "version": "1.0",
- "filetype": "sdist",
- "classifiers": FieldStorage(),
- },
- "classifiers: Should not be a tuple.",
- ),
-
- # keywords are a FieldStorage
- (
- {
- "metadata_version": "1.2",
- "name": "example",
- "version": "1.0",
- "filetype": "sdist",
- "keywords": FieldStorage(),
- },
- "keywords: Should not be a tuple.",
- ),
- ],
+ [({}, "None is an invalid value for Metadata-Version. " "Error: This field is required. " "see " "https://packaging.python.org/specifications/core-metadata"), ({"metadata_version": "-1"}, "'-1' is an invalid value for Metadata-Version. " "Error: Unknown Metadata Version " "see " "https://packaging.python.org/specifications/core-metadata"), ({"metadata_version": "1.2"}, "'' is an invalid value for Name. " "Error: This field is required. " "see " "https://packaging.python.org/specifications/core-metadata"), ({"metadata_version": "1.2", "name": "foo-"}, "'foo-' is an invalid value for Name. " "Error: Must start and end with a letter or numeral and " "contain only ascii numeric and '.', '_' and '-'. " "see " "https://packaging.python.org/specifications/core-metadata"), ({"metadata_version": "1.2", "name": "example"}, "'' is an invalid value for Version. " "Error: This field is required. " "see " "https://packaging.python.org/specifications/core-metadata"), ({"metadata_version": "1.2", "name": "example", "version": "dog"}, "'dog' is an invalid value for Version. " "Error: Must start and end with a letter or numeral and " "contain only ascii numeric and '.', '_' and '-'. " "see " "https://packaging.python.org/specifications/core-metadata"), ({"metadata_version": "1.2", "name": "example", "version": "1.0", "md5_digest": "bad"}, "filetype: This field is required."), ({"metadata_version": "1.2", "name": "example", "version": "1.0", "filetype": "bdist_wat"}, "Error: Python version is required for binary distribution " "uploads."), ({"metadata_version": "1.2", "name": "example", "version": "1.0", "filetype": "bdist_wat", "pyversion": "1.0", "md5_digest": "bad"}, "filetype: Unknown type of file."), ({"metadata_version": "1.2", "name": "example", "version": "1.0", "filetype": "sdist", "pyversion": "1.0"}, "Error: The only valid Python version for a sdist is " "'source'."), ({"metadata_version": "1.2", "name": "example", "version": "1.0", "filetype": "sdist"}, "Error: Must include at least one message digest."), ({"metadata_version": "1.2", "name": "example", "version": "1.0", "filetype": "sdist", "sha256_digest": "an invalid sha256 digest"}, "sha256_digest: " "Must be a valid, hex encoded, SHA256 message digest."), ({"metadata_version": "1.2", "name": "example", "version": "1.0", "filetype": "sdist", "md5_digest": "a fake md5 digest", "summary": "A" * 513}, "'" + "A" * 513 + "' is an invalid value for Summary. " "Error: Field cannot be longer than 512 characters. " "see " "https://packaging.python.org/specifications/core-metadata"), ({"metadata_version": "1.2", "name": "example", "version": "1.0", "filetype": "sdist", "md5_digest": "a fake md5 digest", "summary": "A\nB"}, ("{!r} is an invalid value for Summary. ".format('A\nB') + "Error: Multiple lines are not allowed. " "see " "https://packaging.python.org/specifications/core-metadata")), ({"metadata_version": "1.2", "name": "example", "version": "1.0", "filetype": "sdist", "classifiers": FieldStorage()}, "classifiers: Should not be a tuple."), ({"metadata_version": "1.2", "name": "example", "version": "1.0", "filetype": "sdist", "keywords": FieldStorage()}, "keywords: Should not be a tuple.")],
+ # metadata_version errors.
+ # name errors.
+ # version errors.
+ # filetype/pyversion errors.
+ # digest errors.
+ # summary errors
+ # classifiers are a FieldStorage
+ # keywords are a FieldStorage
)
- def test_fails_invalid_post_data(self, pyramid_config, db_request,
- post_data, message):
+ def test_fails_invalid_post_data(
+ self, pyramid_config, db_request, post_data, message
+ ):
pyramid_config.testing_securitypolicy(userid=1)
db_request.POST = MultiDict(post_data)
from black.
Another example of this with long SQLAlchemy queries containing some inline comments in long chained calls like x.filter().order_by().all()
:
def foo(list_a, list_b):
results = (
User.query
.filter(User.foo == 'bar') # Because foo.
.filter(db.or_(
User.field_a.astext.in_(list_a),
User.field_b.astext.in_(list_b),
))
.filter(User.xyz.is_(None))
# Another comment about the filtering on is_quux goes here.
.filter(db.not_(
User.is_pending.astext.cast(db.Boolean).is_(True)))
.order_by(User.created_at.desc())
.with_for_update(key_share=True)
.all())
return results
becomes
def foo(list_a, list_b):
results = (
User.query.filter(User.foo == 'bar').filter(db.or_(User.field_a.astext.in_(list_a), User.field_b.astext.in_(list_b))).filter(User.xyz.is_(None)).filter(db.not_(User.is_pending.astext.cast(db.Boolean).is_(True))).order_by(User.created_at.desc()).with_for_update(key_share=True).all() # Because foo.
# Another comment about the filtering on is_quux goes here.
)
return results
This produces extremely long lines, and moves the comments around to the wrong places.
from black.
@wbolster, Black will not support the "fluent interfaces" indentation style that you're employing in your SQLAlchemy queries. Your example is reformatted like this:
def foo(list_a, list_b):
results = (
User.query.filter(User.foo == 'bar').filter( # Because foo.
db.or_(User.field_a.astext.in_(list_a), User.field_b.astext.in_(list_b))
).filter(
User.xyz.is_(None)
)
# Another comment about the filtering on is_quux goes here.
.filter(db.not_(User.is_pending.astext.cast(db.Boolean).is_(True))).order_by(
User.created_at.desc()
).with_for_update(
key_share=True
).all()
)
return results
See #67 for more reference.
from black.
Damn, I find the fluent interfaces way nicer for SQLAlchemy queries :) ah well.
from black.
Related Issues (20)
- INTERNAL ERROR: Black produced invalid code: f-string: expecting '}' HOT 1
- GitHub Action: Option to parse version from pyproject.toml
- When reformatting a triple-quote string, black fails with an INTERNAL ERROR: Black produced code that is not equivalent to the source
- Empty line and `...` and "unindent does not match any outer indentation level" HOT 4
- #myomin
- Incorrectly strips tuple brackets from single entry tuple
- Standalone comments still partially broken
- Black keeps reformatting some code chunks back and forth between 2 different representations HOT 6
- formatting fails if the file is located on a network drive HOT 4
- line-length is not working as intended HOT 1
- newline after opening braces causes parser error HOT 1
- Docstrings not part of a function are incorrectly labeled as non-equivalent code HOT 1
- A bug when replacing quote variations HOT 1
- black 24.4.0 returns error when parsing valid Python fstring sentence HOT 1
- f-string internal formatting to be consistent with non-f-string formatting HOT 1
- INTERNAL ERROR HOT 1
- precommit black doesn't read from `pyproject.toml` file. HOT 1
- Line too long: string literal doesn't get split HOT 1
- Black fails with match-case statement with multiple branches HOT 2
- PEP 701 support breaks stability policy HOT 10
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from black.