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

Add final declarations to the library constants. #5275

Closed
asvetlov opened this issue Nov 23, 2020 · 3 comments
Closed

Add final declarations to the library constants. #5275

asvetlov opened this issue Nov 23, 2020 · 3 comments
Labels

Comments

@asvetlov
Copy link
Member

The library has many constant definitions that are declared as NAME = 'val', e.g. https://github.com/aio-libs/aiohttp/blob/master/aiohttp/client.py#L161

We need to add Final type hint to let users know that these constants should be considered as immutable (this hint doesn't prevent the actual modification and fully backward compatible).

from typing_extensions import Final  # support Python < 3.8

NAME: Final = 'val'
@WisdomPill
Copy link
Member

Hello @asvetlov !

I would be glad to step in and make a PR, are there other places that come to your mind that have these kind of constants?

@asvetlov
Copy link
Member Author

Basically, any module-level assignment falls into one of three categories:

  1. __all__ = ... Not sure what to do. Maybe nothing.
  2. Type alias, e.g. _BytesIterator = AsyncIterator[bytes]. Nothing to do here.
  3. Constant assignment. aiohttp has no global variables at all IIRC but has very many global constants. aiohttp/hdrs.py is a good example.

asvetlov added a commit that referenced this issue Dec 17, 2020
Co-authored-by: Andrew Svetlov <andrew.svetlov@gmail.com>
asvetlov pushed a commit that referenced this issue Dec 17, 2020
Co-authored-by: Andrew Svetlov <andrew.svetlov@gmail.com>.
(cherry picked from commit 3be8a68)

Co-authored-by: Anas <anas.el.amraoui@live.com>
asvetlov added a commit that referenced this issue Dec 17, 2020
Co-authored-by: Andrew Svetlov <andrew.svetlov@gmail.com>.
(cherry picked from commit 3be8a68)

Co-authored-by: Anas <anas.el.amraoui@live.com>
@WisdomPill
Copy link
Member

Closing, it was merged almost a month ago

commonism pushed a commit to commonism/aiohttp that referenced this issue Apr 27, 2021
Co-authored-by: Andrew Svetlov <andrew.svetlov@gmail.com>
commonism pushed a commit to commonism/aiohttp that referenced this issue Apr 27, 2021
Co-authored-by: Andrew Svetlov <andrew.svetlov@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants