Removes leading spaces from all lines of code uniformly in the gr.Code() component (#3556)

* code changes

* changelog
This commit is contained in:
Abubakar Abid 2023-03-20 22:07:46 -07:00 committed by GitHub
parent ce20f1ba20
commit c1b5d42cd2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 3 deletions

View File

@ -8,8 +8,11 @@ No changes to highlight.
## Bug Fixes:
- Removes leading spaces from all lines of code uniformly in the `gr.Code()` component. By [@abidlabs](https://github.com/abidlabs) in [PR 3556](https://github.com/gradio-app/gradio/pull/3556)
- Fixed broken login page, by [@aliabid94](https://github.com/aliabid94) in [PR 3529](https://github.com/gradio-app/gradio/pull/3529)
## Documentation Changes:
No changes to highlight.

View File

@ -5593,10 +5593,14 @@ class Code(Changeable, IOComponent, SimpleSerializable):
}
def postprocess(self, y):
if y is not None and isinstance(y, tuple):
if y is None:
return None
elif isinstance(y, tuple):
with open(y[0]) as file_data:
return file_data.read()
return y
else:
unindented_y = inspect.cleandoc(y)
return unindented_y
@staticmethod
def update(

View File

@ -2578,7 +2578,11 @@ class TestCode:
assert code.preprocess("# hello friends") == "# hello friends"
assert code.preprocess("def fn(a):\n return a") == "def fn(a):\n return a"
assert code.postprocess("def fn(a):\n return a") == "def fn(a):\n return a"
assert code.postprocess(
"""
def fn(a):
return a
""") == "def fn(a):\n return a"
test_file_dir = Path(Path(__file__).parent, "test_files")
path = str(Path(test_file_dir, "test_label_json.json"))