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

Marking constants as Final #208

Closed
wants to merge 8 commits into from
Closed

Marking constants as Final #208

wants to merge 8 commits into from

Conversation

deedy5
Copy link
Contributor

@deedy5 deedy5 commented Aug 14, 2022

From mypy docs:
You can use the typing.Final qualifier to indicate that a name or attribute should not be reassigned, redefined, or overridden. This is often useful for module and class level constants as a way to prevent unintended modification. Mypy will prevent further assignments to final names in type-checked code:

Testing after mypy compiling:

python3 setup.py --use-mypyc build_ext --inplace

Before commit:

------------------------------
--> Chardet Conclusions
   --> Avg: 0.1224901914893617s
   --> 99th: 0.73647s
   --> 95th: 0.17915s
   --> 50th: 0.01755s
------------------------------
--> Charset-Normalizer Conclusions
   --> Avg: 0.010322106382978723s
   --> 99th: 0.11215s
   --> 95th: 0.05355s
   --> 50th: 0.00428s
------------------------------
--> Charset-Normalizer / Chardet: Performance Сomparison
   --> Avg: x11.87
   --> 99th: x6.57
   --> 95th: x3.35
   --> 50th: x4.1

After commit:

------------------------------
--> Chardet Conclusions
   --> Avg: 0.12217872340425531s
   --> 99th: 0.72175s
   --> 95th: 0.17481s
   --> 50th: 0.01731s
------------------------------
--> Charset-Normalizer Conclusions
   --> Avg: 0.01016231914893617s
   --> 99th: 0.1085s
   --> 95th: 0.05219s
   --> 50th: 0.00419s
------------------------------
--> Charset-Normalizer / Chardet: Performance Сomparison
   --> Avg: x12.02
   --> 99th: x6.65
   --> 95th: x3.35
   --> 50th: x4.13

@codecov-commenter
Copy link

codecov-commenter commented Aug 14, 2022

Codecov Report

Merging #208 (a18ab48) into 3.0 (0262569) will increase coverage by 0.03%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##              3.0     #208      +/-   ##
==========================================
+ Coverage   90.05%   90.08%   +0.03%     
==========================================
  Files          11       11              
  Lines        1166     1170       +4     
==========================================
+ Hits         1050     1054       +4     
  Misses        116      116              
Impacted Files Coverage Δ
charset_normalizer/constant.py 100.00% <100.00%> (ø)

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@Ousret Ousret self-requested a review August 15, 2022 14:00
Copy link
Owner

@Ousret Ousret left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are close to the margin error regarding the performance gap. Using Final does not strike me as useful now.
I am considering dropping Python 3.6 but certainly not 3.7 and adding a mandatory dependency in order to exploit "Final" is a hard no for me.

from codecs import BOM_UTF8, BOM_UTF16_BE, BOM_UTF16_LE, BOM_UTF32_BE, BOM_UTF32_LE
from encodings.aliases import aliases
from re import IGNORECASE, compile as re_compile
from typing import Dict, List, Set, Union

if sys.version_info < (3, 8):
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding a mandatory dependency for a single typing annotation bugs me.

@@ -8,3 +8,4 @@ black==22.6.0
flake8==5.0.4
mypy==0.971
isort
typing_extensions
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test passes only because it requires installing all dev reqs. In live mode, it would crash because typing_ext is not found.

@Ousret Ousret closed this Aug 15, 2022
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.

None yet

3 participants