-
-
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
Prevent list
method from shadowing list
in type annotations
#184
base: master
Are you sure you want to change the base?
Conversation
For the builtin type shallowing problem, I need to do some check about this. This PR includes too much changes and i can not review on it. Could you please commit the necessary code only without re-generate the openapi code?
Currently, githubkit is checked with pyright, excluding the generated code. I will add an pyright action first to check if there are other issues. Mypy is not primary supported, it will produce many type inferencing errors in complex cases (such as githubkit's paginator).
httpx defines the types here. I'm not sure which version of httpx you are using? |
Yes, sure! I'll update this tomorrow to keep (the only) non-autogen change in this PR. Re mypy: actually after fixing autogen there were only ~10 non-strict mypy errors, all either trivial to fix or worth a type-ignore. I can push and show it after merging solution to this critical issue. Re httpx: sorry, my bad, QueryParamTypes = Union[
"QueryParams",
Mapping[str, Union[PrimitiveData, Sequence[PrimitiveData]]],
List[Tuple[str, PrimitiveData]],
Tuple[Tuple[str, PrimitiveData], ...],
str,
bytes,
] either a list or a tuple of https://github.com/encode/httpx/blob/10b7295922741b91a15751029e6ad3e8e5efb9f3/httpx/_urls.py#L438 Replacing that with |
…gnature (without autogen).
I pushed the isolated change; all other files are modified by autogen - please run it yourself in whichever way is convenient for you. |
I checked the example code in pyright, the shadow issue does not happen. I'm not sure why the behavior is different between pyright and mypy. If i remove the |
Hm, thanks, that might indeed be a |
Currently some features do not support type checking with
mypy
due to invalid type hints in the library. For example, the following:will produce
mypy
errors. A small repro to explain the problem:The most common solution for this problem is to use
builtins.list
in such cases, which I do in this PR. Unfortunately, the schema was recently updated, so there are unrelated diffs withs moved/added classes.To prevent similar issues from appearing in future, I suggest to add a
mypy
(and probablypyright
) check to the project CI. I will submit a PR to do so once this is merged (those changes are smaller but still overlap with codegen, because we need a few ignore comments until https://peps.python.org/pep-0747/ is approved and implemented). There are a few type errors to correct, but those are mostly simple. In particular, #176 introduced a bug:QueryParamTypes
andHeaderTypes
must stick todict
andlist
because upstream httpx declares so and explicitly checks withisinstance
, so passing some other Mapping or Sequence will either result in a crash or produce unexpected results.