diff --git a/CHANGELOG.md b/CHANGELOG.md index dc02ac4cd..cf41f2587 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,7 @@ and [PEP 440](https://www.python.org/dev/peps/pep-0440/). - `fpdf.FPDF()` constructor now accepts ints or floats as a unit, and raises a `ValueError` if an invalid unit is provided. ### Fixed +- `Template.parse_csv`: preserving numeric values when using CSV based templates - [#205](https://github.com/PyFPDF/fpdf2/pull/205) - the code snippet to generate Code 39 barcodes in the documentation was missing the start & end `*` characters. This has been fixed, and a warning is now triggered by the [`FPDF.code39`](https://pyfpdf.github.io/fpdf2/fpdf/fpdf.html#fpdf.fpdf.FPDF.code39) method when those characters are missing. diff --git a/fpdf/util.py b/fpdf/util.py index e48778641..135cca9b2 100644 --- a/fpdf/util.py +++ b/fpdf/util.py @@ -1,14 +1,15 @@ import locale from typing import Union, Iterable -try_to_type_known_types = [ +_TRY_TO_TYPE_KNOWN_TYPES = ( int, float, -] +) def try_to_type(value): - for known_type in try_to_type_known_types: + "Try to convert a string into a number" + for known_type in _TRY_TO_TYPE_KNOWN_TYPES: try: return known_type(value) except ValueError: diff --git a/test/template/test_template.py b/test/template/test_template.py index 2298e415c..cf80b47d3 100644 --- a/test/template/test_template.py +++ b/test/template/test_template.py @@ -134,13 +134,11 @@ def test_template_nominal_csv(tmp_path): tmpl = Template(format="A4", title="Sample Invoice") tmpl.parse_csv(HERE / "mycsvfile.csv", delimiter=";") tmpl.add_page() - tmpl.render() - assert_pdf_equal(tmpl.pdf, HERE / "template_nominal_csv.pdf", tmp_path) + assert_pdf_equal(tmpl, HERE / "template_nominal_csv.pdf", tmp_path) tmpl = Template(format="A4", title="Sample Invoice") tmpl.parse_csv(HERE / "mycsvfile.csv", delimiter=";", encoding="utf-8") tmpl.add_page() - tmpl.render() - assert_pdf_equal(tmpl.pdf, HERE / "template_nominal_csv.pdf", tmp_path) + assert_pdf_equal(tmpl, HERE / "template_nominal_csv.pdf", tmp_path) def test_template_code39(tmp_path): # issue-161