Skip to content
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

breaking change in 22.1.0 TypeError: set object expected; got list #2829

Closed
asottile opened this issue Jan 29, 2022 · 7 comments
Closed

breaking change in 22.1.0 TypeError: set object expected; got list #2829

asottile opened this issue Jan 29, 2022 · 7 comments
Labels
R: rejected This will not be worked on T: bug Something isn't working

Comments

@asottile
Copy link
Contributor

this worked fine in previous versions but was broken with the most recently release

here's the calling code: https://github.com/asottile/blacken-docs/blob/fb39015204c88c8f4f7365d7b4ac049ea8cb6450/blacken_docs.py#L237-L241

Describe the bug

FileMode changed in a backward incompatible way in 22.1.0

To Reproduce

here is the minimal reproduction

python3 -c 'import black; black.FileMode([])'
$ python3 -c 'import black; black.FileMode([])'
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "<string>", line 3, in __init__
TypeError: set object expected; got list

Expected behavior

this used to work

Environment

  • Black's version: 22.1.0
  • OS and Python version: 3.8.10 on ubuntu 20.04

Additional context

this is breaking blacken-docs: adamchainz/blacken-docs#141

@JelleZijlstra
Copy link
Collaborator

This is a consequence of mypyc, which adds strict runtime type checks as the price for improved performance. The first argument to Mode is a set: https://github.com/psf/black/blob/main/src/black/mode.py#L139.

I am not inclined to change this back. We don't have a publicly documented API, and to the extent we do, the type annotations already say you need to pass a set, not a list.

@asottile
Copy link
Contributor Author

there seems to at least be an intent that this is public -- given the comment here:

black/src/black/__init__.py

Lines 102 to 103 in d038a24

# Legacy name, left for integrations.
FileMode = Mode

and when the code was written FileMode utilized attrs.Factory to convert to a set -- 36d3c51

@asottile
Copy link
Contributor Author

it looks like it was unintentionally changed to disallow iterables here: f2ea461 (a confusion between default_factory and Factory)

@JelleZijlstra
Copy link
Collaborator

The history here isn't really relevant. Even if we made some half-hearted backward compatibility hacks in the past, this was never a documented public API, and we can and do change it in incompatible ways without warning. That will continue to be the case until #779 is resolved. One API-like structure we have are the type annotations, and those already said Set in the previous release.

We could probably fix your use case by using an annotation like Collection instead of Set, but at the moment this doesn't feel like it's worth a hotfix release. It's obviously also very easy to fix on your side.

@asottile
Copy link
Contributor Author

I think I would prefer black fix the regression rather than having to adjust my code

chr1st1ank added a commit to chr1st1ank/narrow-down that referenced this issue Jan 30, 2022
@felix-hilden
Copy link
Collaborator

felix-hilden commented Jan 30, 2022

I'll have to agree with Jelle here. Additionally:

  • Set is a better type hint, we wouldn't want lists of duplicate target versions
  • We were in beta for the longest time so things are bound to change. Pinning a beta package is advisable, especially if one is using undocumented APIs, stable as they may seem
  • We still supply a source distribution for which this works just fine: pip install black --no-binary :all: (although I can't remember if the missing conversion has some effect later on)

I feel for you because of the breakage, but I'll echo Jelle: I'm not inclined to change anything here. But we'll continue discussing the public API! Personally, I'm interested in taking care of it pretty soon so people can start using Black within Python as well 👍

@felix-hilden felix-hilden added the R: rejected This will not be worked on label Jan 30, 2022
@asottile
Copy link
Contributor Author

I'm a bit disappointed in the choice, this feels very much like a "we're a bigger project so do what we say" decision rather than one which is helpful for the community and integrations

ChristopherSzczyglowski added a commit to ChristopherSzczyglowski/python_package_template that referenced this issue May 21, 2022
ChristopherSzczyglowski added a commit to ChristopherSzczyglowski/python_package_template that referenced this issue May 21, 2022
* Update black to stable version

Also remove shebang pre-commit check as it is just hassle

* Disable blacken-docs until this regression bug is fixed: psf/black#2829
brianaydemir added a commit to HTPhenotyping/htcondor_file_transfer that referenced this issue May 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
R: rejected This will not be worked on T: bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants