-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
Type of default value for attrs.field()
is revealed as Union[builtins.int, None]
#16174
Comments
Hi @Tinche! I noticed you sumitted a PR to revert some problematic behaviour introduced by that commit I bisected this to (#15393) and then @hauntsaninja proposed an alternative (#15688), so I wanted you guys to get this friendly ping. Am I missing something or is there already some fix in the works for this? Thanks! |
Hi, this is the first I'm hearing of this so I don't think we have a fix in the works. That said, I'm not sure this is easily fixable (except that the default type should actually be The type of I see two solutions:
EDIT: The default value could also be an instance of |
The upgrade of mypy from 1.5.1 to 1.6.0 introduces this error: src/pykmp/client.py: note: In member "send_request" of class "ClientCommunicator": src/pykmp/client.py:136:36: error: Incompatible default for argument "destination_address" (default has type "int | None", argument has type "int") [assignment] For more information see python/mypy#16174. Because it's unclear if this typing complaint can be fixed properly, this changes the destination address variable into a simple module level constant for now.
Thanks for the thoughts and info. For now I've worked around the error and just made it a simple constant reused by both cases (see commit referenced above) and I think it's not a big deal. |
I actually put in some work in the meantime to see if this is achievable. I think it's probably worthwhile but it'll need an attrs release as well, and I'm not sure how to coordinate exactly. |
Bug Report
Default (
default=
) value forattrs.field()
type is revealed asUnion[builtins.int, None]
where the Union with None is unexpected. While this used to be revealed asAny
, this shows up as a regression, bisected to 391ed853f (PR #15021, mypy master, unreleased).To Reproduce
Expected Behavior
Actual Behavior
on master (tested 9edda9a):
(my project fails, suspected mypy bug / imperfect type inference)
On 1.5.1:
(my project passes, albeit without a proper type check)
Your Environment
--strict --show-error-context --show-column-numbers
mypy.ini
(and other config files): n/aProject to test on if you want (100% mypy-strict compatible on 1.5.1 and master otherwise): https://github.com/gertvdijk/PyKMP
The text was updated successfully, but these errors were encountered: