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

line_number no longer valid in latest version of black #2

Closed
xoolive opened this issue Mar 22, 2019 · 5 comments
Closed

line_number no longer valid in latest version of black #2

xoolive opened this issue Mar 22, 2019 · 5 comments

Comments

@xoolive
Copy link

xoolive commented Mar 22, 2019

The line_number parameter seems no longer valid in latest version of black which makes lab_black fail (silently).

The following quick fix seems to work ok for now, though I am not sure it is enough for addressing the issue properly.

if sys.version_info >= (3, 6, 0):
    from black import format_str, FileMode

    def _format_code(code):
        return format_str(src_contents=code, mode=FileMode())

Just for the record, since lab_black failed silently, I would recommend to change

except (ValueError, TypeError):
    pass

into

except (ValueError, TypeError) as e:
    logging.warn(e)
@dnanhkhoa
Copy link
Owner

Thank you for raising up this issue. I think that your solution is fine, I will check and update it as soon as possible. Thanks.

@MarvinT
Copy link

MarvinT commented Mar 27, 2019

https://gist.github.com/MarvinT/a072aa992e977496974aaf492287b08c
and
https://marvint.github.io/Black-Jupyter/

Have examples for fixing this problem or an alternative method using code-prettify.

@dnanhkhoa
Copy link
Owner

Hi @xoolive,
I have fixed this issue using the code you suggested, also tested on both Jupyter Lab and Jupyter Notebook and it works fine, so please update to the latest version. Thank you.

@dnanhkhoa
Copy link
Owner

Hi @MarvinT,
Thank you for sharing, I have checked your repo out and see that it's really helpful and convenient. :D

@xoolive
Copy link
Author

xoolive commented Mar 27, 2019

Excellent! Works like a charm on my side.

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