-
Notifications
You must be signed in to change notification settings - Fork 416
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
Check for non-None
expectations
#214
Comments
@AA-Turner was there tooling/scripts etc. that allowed you to spot these potential problems? Thanks. |
Mainly by running AA-Turner@a77ac16 (in https://github.com/AA-Turner/python-phonenumbers/tree/find-errors) explicitly denotes the errors by adding either Typeshed does note that best practice is to avoid union return types (https://github.com/python/typeshed/blob/master/CONTRIBUTING.md#conventions -- "avoid union return types: python/mypy#1693"), although it notes that detecting where handling There are 21 functions or methdos that return union types currently: Public API:
Internal public functions:
Internal private functions/methods:
I'd suggest most of the errors come from these -- as statically it can't be determined what the function will return, given that it is a value based call. A |
Hmm, I'm not getting many errors with this ( |
CI run also has no errors: https://github.com/daviddrysdale/python-phonenumbers/runs/3542166579?check_suite_focus=true |
Ahh, I see the difference -- I pulled in my standard mypy config file, which sets configs equal to the following If you run with that, you should see all the errors. The actual config is in an untracked # mypy configuration
[tool.mypy]
# help finding errors
show_error_codes = true
show_error_context = true
# exclude protobuf directory
exclude = "pb2/.*"
# stubs
warn_incomplete_stub = true
# mypy --strict config:
warn_unused_configs = true
disallow_any_generics = true
disallow_subclassing_any = true
# disallow_untyped_calls = true # turn off for tests/
# disallow_untyped_defs = true # turn off for tests/
disallow_incomplete_defs = true
check_untyped_defs = true
disallow_untyped_decorators = true
no_implicit_optional = true
warn_redundant_casts = true
warn_unused_ignores = true
warn_return_any = true
no_implicit_reexport = true
strict_equality = true A |
I wonder if there's any way to persuade |
I tried the obvious thing (to me) of a function that calls There are a few threads/issues around unittest and type narrowing, but from a few years ago (~2018) and with no resolution it seems. Another thing I thought of was a genericly typed overload function on the same lines as the above (replacing calls to So seems this works by default with A |
From #200 (comment):
The text was updated successfully, but these errors were encountered: