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

[FEATURE] Please add generics #81

Open
spacether opened this issue Jun 21, 2023 · 1 comment
Open

[FEATURE] Please add generics #81

spacether opened this issue Jun 21, 2023 · 1 comment
Labels
Needs: Help Extra attention is needed Needs: Test Hey, it compiles! Ship it! Priority: Low Not a big problem... Status: Wontfix This will not be worked on Type: Enhancement New feature or request

Comments

@spacether
Copy link

spacether commented Jun 21, 2023

Welcome! Before you write your Feature Request, please read below:

Is your feature request related to a problem? Please describe.
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

Describe the solution you'd like
Please add generics to frozendict
One should be able to define frozendict key and value types like so:

>>> import frozendict
>>> f = frozendict.frozendict[str, int]
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: 'type' object is not subscriptable

this works

>>> import typing
>>> f = typing.Dict[str, int]

Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.

Additional context
Add any other context or screenshots about the feature request here.

Related:

@Marco-Sulla
Copy link
Owner

Marco-Sulla commented Jun 24, 2023

frozendict is a C extension, so support for generics is for Python 3.9+:

marco@buzz:~/sources/python-frozendict$ . venv_3_8/bin/activate
(venv_3_8) marco@buzz:~/sources/python-frozendict$ python
Python 3.8.17 (tags/v3.8.17-dirty:9a2d5311d1, Jun 24 2023, 14:15:31) 
[GCC 11.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import frozendict
>>> frozendict.frozendict[str, int]
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: 'type' object is not subscriptable
>>> dict[str, int]
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: 'type' object is not subscriptable
>>> 
(venv_3_8) marco@buzz:~/sources/python-frozendict$ deactivate 
marco@buzz:~/sources/python-frozendict$ . venv_3_9/bin/activate
(venv_3_9) marco@buzz:~/sources/python-frozendict$ python
Python 3.9.17 (tags/v3.9.17-dirty:0d3cd4eb66, Jun 24 2023, 14:33:23) 
[GCC 11.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import frozendictint
>>> frozendict.frozendict[str, int]
frozendict.frozendict[str, int]
>>> dict[str, int]
dict[str, int]
>>>

immutabledict is a pure py implementation. frozendict has also a pure py implementation, and I can add generics to it for all supported py versions.

The question is: is it worth it? Python 3.8 EOL is in 14 Oct 2024. Consider to upgrade your Python. Python 3.10-3.11 are really faster.

If you can't, I can consider to add it to my TODO list (after implementing C extension for 3.11 and deepfreeze).

@Marco-Sulla Marco-Sulla added Type: Enhancement New feature or request Needs: Help Extra attention is needed Status: Wontfix This will not be worked on Priority: Low Not a big problem... Needs: Test Hey, it compiles! Ship it! labels Dec 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs: Help Extra attention is needed Needs: Test Hey, it compiles! Ship it! Priority: Low Not a big problem... Status: Wontfix This will not be worked on Type: Enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants