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

Question: Should I not be using Mode (FileMode)? #2256

Closed
haxsaw opened this issue May 25, 2021 · 4 comments
Closed

Question: Should I not be using Mode (FileMode)? #2256

haxsaw opened this issue May 25, 2021 · 4 comments

Comments

@haxsaw
Copy link

haxsaw commented May 25, 2021

It's been suggested to me that Mode (FileMode) is not for 'real world' use for formatting code fragments in memory prior to writing to a file. Besides FileMode being legacy and probably should be replaced with just Mode, is there any reason not to use it in a system where I want to format in memory?

@felix-hilden
Copy link
Collaborator

felix-hilden commented May 25, 2021

If you're referring to the classes inside Black's source, the answer is: you should probably not be using them for formatting of any sort because their implementation (or existence) may change at any time. A public Python api is being planned in #779. It would most likely introduce a single function for formatting code as strings.

@haxsaw
Copy link
Author

haxsaw commented May 25, 2021

That's a shame, but I get it. I'm generating code dynamically and have been using black to format each class as I go (I can see from 779 that I have company). I'll consider my options. Thanks for the swift reply.

@haxsaw haxsaw closed this as completed May 25, 2021
@felix-hilden
Copy link
Collaborator

You're most welcome! Yeah let's hope that the API is introduced soon 😃 until then, I'd not expect the implementation to change drastically, but you might want to be careful as always, that's all.

@JelleZijlstra
Copy link
Collaborator

However, the public API is quite likely to look like black.format_str(mode=Mode()). FileMode is a deprecated alias for Mode I believe (might be the other way around). If I were you, I'd use format_str() and be careful the next few times Black makes a release.

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

3 participants