https://pantsbuild.org/ logo
w

witty-crayon-22786

10/27/2021, 8:42 PM
for whom it may concern:
Copy code
# python3.8:
>>> cast(dict[str, str], dict())
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: 'type' object is not subscriptable
Copy code
# python3.9
>>> cast(dict[str, str], dict())
{}
(all this to say: i broke some code)
h

hundreds-father-404

10/27/2021, 8:43 PM
yeah, have to use
""
for
cast
because it's not a type hint
It's clunky, but I personally prefer
cast("dict[str, str]", foo)
to
Dict[str, str]
w/ an import
b

bitter-ability-32190

10/27/2021, 8:44 PM
from __future__ import annotations
?
h

hundreds-father-404

10/27/2021, 8:44 PM
not for
cast
, which is a normal fucntion call rather than an annotation
☝️ 1
b

bitter-ability-32190

10/27/2021, 8:44 PM
Ah, of course!
w

witty-crayon-22786

10/27/2021, 11:18 PM
so, um: regarding the code i broke (
build-support/bin/generate_docs.py
): should i constrain that to 3.9, or downgrade the syntax? it made it through because
mypy
is happy with either
h

hundreds-father-404

10/28/2021, 12:13 AM
I'm fine with constraining to 3.9 as an M1 user. But not sure if all Pants devs have that. And then it will result in our linters partitioning (maybe that dogfooding is good)
👍 1