mirror of
https://github.com/gradio-app/gradio.git
synced 2024-11-27 01:40:20 +08:00
Removes leading spaces from all lines of code uniformly in the gr.Code()
component (#3556)
* code changes * changelog
This commit is contained in:
parent
ce20f1ba20
commit
c1b5d42cd2
@ -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.
|
||||
|
@ -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(
|
||||
|
@ -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"))
|
||||
|
Loading…
Reference in New Issue
Block a user