refactor(Taxonomy): replace TAXONOMY_URLS with TAXONOMY_MAPPING and a single method to build the url#475
Open
raphodn wants to merge 4 commits intoraphodn/pre-commit-ruff-fixfrom
Open
Conversation
|
raphodn
commented
Apr 25, 2026
| origin = "origin" | ||
| language = "language" | ||
| other_nutritional_substance = "other_nutritional_substance" | ||
| dataset_filename: str |
Member
Author
There was a problem hiding this comment.
added to avoid mypy error
src/openfoodfacts/types.py:901: error: "TaxonomyType" has no attribute "dataset_filename" [attr-defined]
Freso
approved these changes
Apr 25, 2026
Contributor
Freso
left a comment
There was a problem hiding this comment.
One comment/suggestion, but overall LGTM!
Comment on lines
+896
to
+930
| def __new__(cls, value: str, dataset_filename: str): | ||
| """ | ||
| Override __new__ to allow storing the dataset filename | ||
| associated with each taxonomy type. | ||
| """ | ||
| obj = str.__new__(cls, value) | ||
| obj._value_ = value | ||
| obj.dataset_filename = dataset_filename | ||
| return obj | ||
|
|
||
| category = ("category", "categories.full.json") | ||
| ingredient = ("ingredient", "ingredients.full.json") | ||
| label = ("label", "labels.full.json") | ||
| brand = ("brand", "brands.full.json") | ||
| packaging_shape = ("packaging_shape", "packaging_shapes.full.json") | ||
| packaging_material = ("packaging_material", "packaging_materials.full.json") | ||
| packaging_recycling = ("packaging_recycling", "packaging_recycling.full.json") | ||
| country = ("country", "countries.full.json") | ||
| store = ("store", "stores.full.json") | ||
| nova_group = ("nova_group", "nova_groups.full.json") | ||
| packaging = ("packaging", "packaging.full.json") | ||
| additive = ("additive", "additives.full.json") | ||
| vitamin = ("vitamin", "vitamins.full.json") | ||
| mineral = ("mineral", "minerals.full.json") | ||
| amino_acid = ("amino_acid", "amino_acids.full.json") | ||
| nucleotide = ("nucleotide", "nucleotides.full.json") | ||
| allergen = ("allergen", "allergens.full.json") | ||
| state = ("state", "states.full.json") | ||
| data_quality = ("data_quality", "data_quality.full.json") | ||
| origin = ("origin", "origins.full.json") | ||
| language = ("language", "languages.full.json") | ||
| other_nutritional_substance = ( | ||
| "other_nutritional_substance", | ||
| "other_nutritional_substances.full.json", | ||
| ) |
Contributor
There was a problem hiding this comment.
Would it make sense/work to flip these two block around?
Suggested change
| def __new__(cls, value: str, dataset_filename: str): | |
| """ | |
| Override __new__ to allow storing the dataset filename | |
| associated with each taxonomy type. | |
| """ | |
| obj = str.__new__(cls, value) | |
| obj._value_ = value | |
| obj.dataset_filename = dataset_filename | |
| return obj | |
| category = ("category", "categories.full.json") | |
| ingredient = ("ingredient", "ingredients.full.json") | |
| label = ("label", "labels.full.json") | |
| brand = ("brand", "brands.full.json") | |
| packaging_shape = ("packaging_shape", "packaging_shapes.full.json") | |
| packaging_material = ("packaging_material", "packaging_materials.full.json") | |
| packaging_recycling = ("packaging_recycling", "packaging_recycling.full.json") | |
| country = ("country", "countries.full.json") | |
| store = ("store", "stores.full.json") | |
| nova_group = ("nova_group", "nova_groups.full.json") | |
| packaging = ("packaging", "packaging.full.json") | |
| additive = ("additive", "additives.full.json") | |
| vitamin = ("vitamin", "vitamins.full.json") | |
| mineral = ("mineral", "minerals.full.json") | |
| amino_acid = ("amino_acid", "amino_acids.full.json") | |
| nucleotide = ("nucleotide", "nucleotides.full.json") | |
| allergen = ("allergen", "allergens.full.json") | |
| state = ("state", "states.full.json") | |
| data_quality = ("data_quality", "data_quality.full.json") | |
| origin = ("origin", "origins.full.json") | |
| language = ("language", "languages.full.json") | |
| other_nutritional_substance = ( | |
| "other_nutritional_substance", | |
| "other_nutritional_substances.full.json", | |
| ) | |
| category = ("category", "categories.full.json") | |
| ingredient = ("ingredient", "ingredients.full.json") | |
| label = ("label", "labels.full.json") | |
| brand = ("brand", "brands.full.json") | |
| packaging_shape = ("packaging_shape", "packaging_shapes.full.json") | |
| packaging_material = ("packaging_material", "packaging_materials.full.json") | |
| packaging_recycling = ("packaging_recycling", "packaging_recycling.full.json") | |
| country = ("country", "countries.full.json") | |
| store = ("store", "stores.full.json") | |
| nova_group = ("nova_group", "nova_groups.full.json") | |
| packaging = ("packaging", "packaging.full.json") | |
| additive = ("additive", "additives.full.json") | |
| vitamin = ("vitamin", "vitamins.full.json") | |
| mineral = ("mineral", "minerals.full.json") | |
| amino_acid = ("amino_acid", "amino_acids.full.json") | |
| nucleotide = ("nucleotide", "nucleotides.full.json") | |
| allergen = ("allergen", "allergens.full.json") | |
| state = ("state", "states.full.json") | |
| data_quality = ("data_quality", "data_quality.full.json") | |
| origin = ("origin", "origins.full.json") | |
| language = ("language", "languages.full.json") | |
| other_nutritional_substance = ( | |
| "other_nutritional_substance", | |
| "other_nutritional_substances.full.json", | |
| ) | |
| def __new__(cls, value: str, dataset_filename: str): | |
| """ | |
| Override __new__ to allow storing the dataset filename | |
| associated with each taxonomy type. | |
| """ | |
| obj = str.__new__(cls, value) | |
| obj._value_ = value | |
| obj.dataset_filename = dataset_filename | |
| return obj |
raphodn
commented
Apr 25, 2026
| other_nutritional_substance = "other_nutritional_substance" | ||
| dataset_filename: str | ||
|
|
||
| def __new__(cls, value: str, dataset_filename: str): |
Member
Author
There was a problem hiding this comment.
logic taken from https://docs.python.org/3/howto/enum.html#when-to-use-new-vs-init
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Description
Following #466
Solution
TaxonomyTypetype: add a newdataset_filenamekey &dataset_pathproperty_generate_file_pathand use both TAXONOMY_MAPPING & TaxonomyType.dataset_pathRelated issue(s)