-
Notifications
You must be signed in to change notification settings - Fork 283
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
Enable strict typing #984
Enable strict typing #984
Conversation
# Define custom type for kernel connection info | ||
KernelConnectionInfo = Dict[str, Union[int, str, bytes]] | ||
|
||
|
||
def write_connection_file( | ||
fname: Optional[str] = None, | ||
fname: str | None = None, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I dont' think we should do this if we still support 3.8 and 3.9, this beciome valid syntax, but typing.get_type_hints()
will fail on |
for Union syntax on 3.8 and 3.9, so we risk breaking things.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
from __future__ import annotations
from typing import Optional, get_type_hints
def write_connection_file(fname: str | None = None) -> None:
pass
get_type_hints(write_connection_file)
$ python f.py
Traceback (most recent call last):
File "/Users/bussonniermatthias/dev/jupyter_client/f.py", line 9, in <module>
get_type_hints(write_connection_file)
File "/Users/bussonniermatthias/miniforge3/envs/39/lib/python3.9/typing.py", line 1386, in get_type_hints
value = _eval_type(value, globalns, localns)
File "/Users/bussonniermatthias/miniforge3/envs/39/lib/python3.9/typing.py", line 254, in _eval_type
return t._evaluate(globalns, localns, recursive_guard)
File "/Users/bussonniermatthias/miniforge3/envs/39/lib/python3.9/typing.py", line 493, in _evaluate
eval(self.__forward_code__, globalns, localns),
File "<string>", line 1, in <module>
TypeError: unsupported operand type(s) for |: 'type' and 'NoneType'
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oof, that is frustrating. I've already released several changes with that syntax in other jupyter
libs. Thanks for catching that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, not your fault, it's a common confusion. I wouldn't have caught it if not for a similar problem recently.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well now I'm not so sure what to do, because this also applies to type[]
, set[]
, list[]
, dict[]
, etc. I don't think we need to claim to support type hints for Python 3.8 or 3.9.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At least not at run time.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nothing prevents folks from calling get_type_hints
on their own code, I just verified.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
as you made the PR i think it's fine, but maybe we ca avoid this for subsequent libs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah that sounds like a good plan. I added this to ignores, which I'll use as a template:
# non-pep585-annotation
"UP006",
# non-pep604-annotation
"UP007",
BTW @blink1073 when I run mypy directly instead of via hatch, I get many more errors. Any idea why ? |
The hatch version has some min version pins to pick up newer typings. |
Yeah it helps to update the versions, but I still get some errors. That's fine I can use hatch for now. |
Leave a few rules on for now that would need a lot more work: