Skip to content

Commit 08efed8

Browse files
Simplify printf statement. (pyccel#1972)
This PR simplifies the printf statement in C Language. fixes pyccel#1966 ## Input: `print("Hello world")` ## Previous Output: `printf("%s\n", "Hello world");` ## Output now: `printf("Hello world.\n");` --------- Co-authored-by: Emily Bourne <[email protected]>
1 parent 43c2934 commit 08efed8

File tree

3 files changed

+8
-5
lines changed

3 files changed

+8
-5
lines changed

AUTHORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,4 @@ Contributors
3333
* Varadarajan Rengaraj
3434
* Said Mazouz
3535
* Shoaib Moeen
36+
* Kush Choudhary

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ All notable changes to this project will be documented in this file.
6363
- #1913 : Fix function calls to renamed functions.
6464
- #1930 : Preserve ordering of import targets.
6565
- #1892 : Fix implementation of list function when an iterable is passed as parameter.
66+
- #1972 : Simplified `printf` statement for Literal String.
6667

6768
### Changed
6869

pyccel/codegen/printing/ccode.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -649,11 +649,11 @@ def init_stc_container(self, expr, assignment_var):
649649
----------
650650
expr : TypedAstNode
651651
The object representing the container being printed (e.g., PythonList, PythonSet).
652-
652+
653653
assignment_var : Assign
654-
The assignment node where the Python container (rhs) is being initialized
654+
The assignment node where the Python container (rhs) is being initialized
655655
and saved into a variable (lhs).
656-
656+
657657
Returns
658658
-------
659659
str
@@ -676,7 +676,7 @@ def rename_imported_methods(self, expr):
676676
Rename class methods from user-defined imports.
677677
678678
This function is responsible for renaming methods of classes from
679-
the imported modules, ensuring that the names are correct
679+
the imported modules, ensuring that the names are correct
680680
by prefixing them with their class names.
681681
682682
Parameters
@@ -1186,6 +1186,8 @@ def formatted_args_to_printf(args_format, args, end):
11861186
file=expr.file)],
11871187
unravelled = True)
11881188
code += self._print(body)
1189+
elif isinstance(f, LiteralString):
1190+
args_format.append(f.python_value)
11891191
else:
11901192
arg_format, arg = self.get_print_format_and_arg(f)
11911193
args_format.append(arg_format)
@@ -2683,4 +2685,3 @@ def indent_code(self, code):
26832685
pretty.append("%s%s" % (tab*level, line))
26842686
level += increase[n]
26852687
return pretty
2686-

0 commit comments

Comments
 (0)