-
-
Notifications
You must be signed in to change notification settings - Fork 29
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
subscriptable typing #172
Comments
While I understand the details and reason of this behaviour, it caught me off-guard, so I thought I mention it. Maybe the constructor and the type could be different (like list() / List) ? |
The generic types from the You can see the difference in your own example: class MyClass:
lst: List[int]
# ^^^^ Capital L
dc = MyClass(lst=list([1,2,3]))
# ^^^^ lowercase l
And while I understand that the naming convention for the generic The correct method is to either use With from __future__ import annotations
from dataclasses import dataclass
from frozenlist import FrozenList
class MyClass:
lst: FrozenList[int]
dc = MyClass(lst=FrozenList([1,2,3]))
print(dc) or with a forward reference: from __future__ import annotations
from dataclasses import dataclass
from frozenlist import FrozenList
class MyClass:
lst: "FrozenList[int]"
dc = MyClass(lst=FrozenList([1,2,3]))
print(dc) Both forms are recognized and supported by mypy as well. That said, with Python 3.9 now implementing PEP 585, we could look into adding |
Long story short
Subscripting the FrozenList type currently breaks.
I'm guessing a user would expect the FrozenList works the same as standard List as far as typing is concerned...
Example script:
Expected behaviour
I would expect this to work as with List:
Actual behaviour
Your environment
The text was updated successfully, but these errors were encountered: