Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert namespaces to regular templates #1518

Closed
wants to merge 4 commits into from
Closed

Convert namespaces to regular templates #1518

wants to merge 4 commits into from

Conversation

BoboTiG
Copy link
Owner

@BoboTiG BoboTiG commented Jan 17, 2023

Fixes #1494

Another proposal. It requires more code, and we will need to handle new templates when we discover them.

@BoboTiG BoboTiG requested a review from lasconic January 17, 2023 09:31
@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Jan 17, 2023

Sourcery Code Quality Report

❌  Merging this PR will decrease code quality in the affected files by 0.25%.

Quality metrics Before After Change
Complexity 28.74 😞 27.83 😞 -0.91 👍
Method Length 156.77 😞 162.14 😞 5.37 👎
Working memory 11.62 😞 11.60 😞 -0.02 👍
Quality 40.43% 😞 40.18% 😞 -0.25% 👎
Other metrics Before After Change
Lines 3659 3697 38
Changed files Quality Before Quality After Quality Change
tests/test_fr.py 53.12% 🙂 53.13% 🙂 0.01% 👍
wikidict/utils.py 69.19% 🙂 65.00% 🙂 -4.19% 👎
wikidict/lang/ca/__init__.py 17.34% ⛔ 17.31% ⛔ -0.03% 👎
wikidict/lang/de/__init__.py 65.66% 🙂 65.12% 🙂 -0.54% 👎
wikidict/lang/en/__init__.py 19.55% ⛔ 19.53% ⛔ -0.02% 👎
wikidict/lang/es/__init__.py 27.39% 😞 27.32% 😞 -0.07% 👎
wikidict/lang/fr/__init__.py 18.71% ⛔ 18.71% ⛔ 0.00%
wikidict/lang/it/__init__.py 83.13% ⭐ 82.74% ⭐ -0.39% 👎
wikidict/lang/sv/__init__.py 48.29% 😞 48.04% 😞 -0.25% 👎

Here are some functions in these files that still need a tune-up:

File Function Complexity Length Working Memory Quality Recommendation
wikidict/lang/ca/__init__.py last_template_handler 66 ⛔ 505 ⛔ 2.57% ⛔ Refactor to reduce nesting. Try splitting into smaller methods
wikidict/lang/en/__init__.py last_template_handler 63 ⛔ 397 ⛔ 25 ⛔ 4.77% ⛔ Refactor to reduce nesting. Try splitting into smaller methods. Extract out complex expressions
wikidict/lang/fr/__init__.py last_template_handler 70 ⛔ 608 ⛔ 19 ⛔ 5.94% ⛔ Refactor to reduce nesting. Try splitting into smaller methods. Extract out complex expressions
wikidict/lang/es/__init__.py last_template_handler 37 ⛔ 294 ⛔ 25 ⛔ 12.13% ⛔ Refactor to reduce nesting. Try splitting into smaller methods. Extract out complex expressions
wikidict/lang/sv/__init__.py last_template_handler 20 😞 180 😞 18 ⛔ 31.27% 😞 Refactor to reduce nesting. Try splitting into smaller methods. Extract out complex expressions

Legend and Explanation

The emojis denote the absolute quality of the code:

  • ⭐ excellent
  • 🙂 good
  • 😞 poor
  • ⛔ very poor

The 👍 and 👎 indicate whether the quality has improved or gotten worse with this pull request.


Please see our documentation here for details on how these metrics are calculated.

We are actively working on this report - lots more documentation and extra metrics to come!

Help us improve this quality report!

@BoboTiG
Copy link
Owner Author

BoboTiG commented Jan 17, 2023

The update job is running to catch missing templates. If that works for you @lasconic, I'll just add them when it's finished, and re-iterate.

@lasconic
Copy link
Collaborator

Ok. Clever. But do we really want to mess the code so deep ? If we do need to treat some namespaces differently, maybe we should just do it in clean() instead of artificially add templates to process them down the line in each language?
Also, let's hope we don't have actual templates with the same name than namespace...

@BoboTiG
Copy link
Owner Author

BoboTiG commented Jan 17, 2023

I like the current idea, mostly because when the one-time job to handle new templates will be done, it's almost fully automated for upcoming namespace changes (even if it's unlikely to happen on a regular basis).
If we go with special treatments in clean() (I am not opposed to such idea), we'll need to keep a list of namespaces to handle, and another one with ignored ones. I don't know if it's better, worse, or the same.
What I propose: I finish that version, just to have a complete overview of what if requires as code; and you may find some time to try another version. WDYT?

Also, let's hope we don't have actual templates with the same name than namespace...

It seems we are lucky enough: those templates always start with a capital letter. It should be OK.

@BoboTiG
Copy link
Owner Author

BoboTiG commented Jan 17, 2023

Also, let's hope we don't have actual templates with the same name than namespace...

It seems we are lucky enough: those templates always start with a capital letter. It should be OK.

OK, that's not true for Italian, at least. But it doesn't mess with current templates either.

@BoboTiG
Copy link
Owner Author

BoboTiG commented Jan 17, 2023

I moved out from last_template_handler() in 89c61bc, better now.

I'm surprised that English is not using any namespaces.

The last patch for German will come soon.

@lasconic
Copy link
Collaborator

The wiktionary API gave back the "canonical" namespace name in english
https://es.wiktionary.org/w/api.php?action=query&meta=siteinfo&siprop=namespaces

I guess if Fichier needs to be handled differently, then in other languages all namespaces with canonical "File" will have to as well.

@BoboTiG
Copy link
Owner Author

BoboTiG commented Jan 17, 2023

Given the "missing template" line reported by the CI, for now no need to handle more templates.
I started another job just to be sure nothing is missing.

@BoboTiG
Copy link
Owner Author

BoboTiG commented Jan 17, 2023

Do you plan to work on another solution? Or let's put it like that: do you dislike that proposal enough to reject the patch? :)

@lasconic
Copy link
Collaborator

Trying something shorter as we speak

@BoboTiG
Copy link
Owner Author

BoboTiG commented Jan 17, 2023

Superseded by #1530.

@BoboTiG BoboTiG closed this Jan 17, 2023
@BoboTiG BoboTiG deleted the fix-1494 branch January 17, 2023 14:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Smarter link-with-namespace filter
2 participants