Skip to content

Why does Threading.Timer 'function' expect None as return type? #3782

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

Closed
PGijsbers opened this issue Feb 27, 2020 · 5 comments
Closed

Why does Threading.Timer 'function' expect None as return type? #3782

PGijsbers opened this issue Feb 27, 2020 · 5 comments

Comments

@PGijsbers
Copy link
Contributor

The Timer signature specifies that function should have the signature Callable[..., None]. I couldn't find anything in the official Timer documentation on why that would be. In my project I found myself using a function with return value (that I'm not interested in), and don't see why this should not be accepted usage. I think probably the correct signature should be Callable[..., Any]. Could someone clarify?

@JelleZijlstra
Copy link
Member

I agree, it should be Any if the return value is ignored. Feel free to submit a PR!

@PGijsbers
Copy link
Contributor Author

I was working on getting the unit tests up and running, but had some trouble. My normal environment is on Windows (with Anaconda) but this failed to build a wheel for pytype when installing the test requirements. So I went to my backup system, which is the Windows Subsystem for Linux and install seemed to work correctly. However when running python tests/mypy_selftest.py it turned out I had to install Python2.7 (and pip), after that it worked fine.

When running python tests/stubtest_test.py I got the errors below. I'm not sure if those are the errors the documentation refers to that can/should be whitelisted. I installed/updated gdbm (sudo apt install python3.6-gdbm) but this did not fix my issue.
Other tests and flake8 ran fine.

python tests/subtest_test.py output:

/home/pieter/miniconda3/envs/typeshed/bin/python -m mypy.stubtest --ignore-missing-stub --check-typeshed --custom-typeshed-dir . --whitelist tests/stubtest_whitelists/py3_common.txt --whitelist tests/stubtest_whitelists/py36.txt --ignore-positional-only
error: dbm.gnu failed to import: No module named '_gdbm'
Stub: at line 1
MypyFile:1(
  stdlib/3/dbm/gnu.pyi
  IgnoredLines(33, 34))
Runtime:
MISSING

error: os.O_PATH is not present at runtime
Stub: at line 120
builtins.int
Runtime:
MISSING

error: os.O_TMPFILE is not present at runtime
Stub: at line 121
builtins.int
Runtime:
MISSING

error: os.SEEK_DATA is not present at runtime
Stub: at line 86
builtins.int
Runtime:
MISSING

error: os.SEEK_HOLE is not present at runtime
Stub: at line 87
builtins.int
Runtime:
MISSING

error: os.getrandom is not present at runtime
Stub: at line 651
def (size: builtins.int, flags: builtins.int =) -> builtins.bytes
Runtime:
MISSING

error: posix.GRND_NONBLOCK is not present at runtime
Stub: at line 61
builtins.int
Runtime:
MISSING

error: posix.GRND_RANDOM is not present at runtime
Stub: at line 62
builtins.int
Runtime:
MISSING

error: resource.RLIMIT_RTTIME is not present at runtime
Stub: at line 24
builtins.int
Runtime:
MISSING

error: resource.prlimit is not present at runtime
Stub: at line 51
def (pid: builtins.int, resource: builtins.int, limits: Union[Tuple[builtins.int, builtins.int], None]) -> Tuple[builtins.int, builtins.int]
Runtime:
MISSING

error: socket.AF_ALG is not present at runtime
Stub: at line 401
socket.AddressFamily
Runtime:
MISSING

error: socket.ALG_OP_DECRYPT is not present at runtime
Stub: at line 403
builtins.int
Runtime:
MISSING

error: socket.ALG_OP_ENCRYPT is not present at runtime
Stub: at line 404
builtins.int
Runtime:
MISSING

error: socket.ALG_OP_SIGN is not present at runtime
Stub: at line 405
builtins.int
Runtime:
MISSING

error: socket.ALG_OP_VERIFY is not present at runtime
Stub: at line 406
builtins.int
Runtime:
MISSING

error: socket.ALG_SET_AEAD_ASSOCLEN is not present at runtime
Stub: at line 407
builtins.int
Runtime:
MISSING

error: socket.ALG_SET_AEAD_AUTHSIZE is not present at runtime
Stub: at line 408
builtins.int
Runtime:
MISSING

error: socket.ALG_SET_IV is not present at runtime
Stub: at line 409
builtins.int
Runtime:
MISSING

error: socket.ALG_SET_KEY is not present at runtime
Stub: at line 410
builtins.int
Runtime:
MISSING

error: socket.ALG_SET_OP is not present at runtime
Stub: at line 411
builtins.int
Runtime:
MISSING

error: socket.ALG_SET_PUBKEY is not present at runtime
Stub: at line 412
builtins.int
Runtime:
MISSING

error: socket.CAN_BCM is not present at runtime
Stub: at line 309
builtins.int
Runtime:
MISSING

error: socket.CAN_BCM_RX_CHANGED is not present at runtime
Stub: at line 321
builtins.int
Runtime:
MISSING

error: socket.CAN_BCM_RX_DELETE is not present at runtime
Stub: at line 315
builtins.int
Runtime:
MISSING

error: socket.CAN_BCM_RX_READ is not present at runtime
Stub: at line 316
builtins.int
Runtime:
MISSING

error: socket.CAN_BCM_RX_SETUP is not present at runtime
Stub: at line 314
builtins.int
Runtime:
MISSING

error: socket.CAN_BCM_RX_STATUS is not present at runtime
Stub: at line 319
builtins.int
Runtime:
MISSING

error: socket.CAN_BCM_RX_TIMEOUT is not present at runtime
Stub: at line 320
builtins.int
Runtime:
MISSING

error: socket.CAN_BCM_TX_DELETE is not present at runtime
Stub: at line 311
builtins.int
Runtime:
MISSING

error: socket.CAN_BCM_TX_EXPIRED is not present at runtime
Stub: at line 318
builtins.int
Runtime:
MISSING

error: socket.CAN_BCM_TX_READ is not present at runtime
Stub: at line 312
builtins.int
Runtime:
MISSING

error: socket.CAN_BCM_TX_SEND is not present at runtime
Stub: at line 313
builtins.int
Runtime:
MISSING

error: socket.CAN_BCM_TX_SETUP is not present at runtime
Stub: at line 310
builtins.int
Runtime:
MISSING

error: socket.CAN_BCM_TX_STATUS is not present at runtime
Stub: at line 317
builtins.int
Runtime:
MISSING

error: socket.CAN_RAW_FD_FRAMES is not present at runtime
Stub: at line 323
builtins.int
Runtime:
MISSING

error: socket.IPV6_DONTFRAG is not present at runtime
Stub: at line 161
builtins.int
Runtime:
MISSING

error: socket.IPV6_PATHMTU is not present at runtime
Stub: at line 171
builtins.int
Runtime:
MISSING

error: socket.IPV6_RECVPATHMTU is not present at runtime
Stub: at line 176
builtins.int
Runtime:
MISSING

error: socket.MSG_FASTOPEN is not present at runtime
Stub: at line 217
socket.MsgFlag
Runtime:
MISSING

error: socket.NETLINK_CRYPTO is not present at runtime
Stub: at line 448
builtins.int
Runtime:
MISSING

error: socket.SOL_ALG is not present at runtime
Stub: at line 402
builtins.int
Runtime:
MISSING

error: socket.SOL_RDS is not present at runtime
Stub: at line 342
builtins.int
Runtime:
MISSING

error: socket.SO_REUSEPORT is not present at runtime
Stub: at line 267
builtins.int
Runtime:
MISSING

error: socket.TCP_FASTOPEN is not present at runtime
Stub: at line 276
builtins.int
Runtime:
MISSING

error: socket.TCP_USER_TIMEOUT is not present at runtime
Stub: at line 435
builtins.int
Runtime:
MISSING

error: socket.socket.sendmsg_afalg is not present at runtime
Stub: at line 686
def (self: socket.socket, msg: Any =, *, op: Any, iv: Any =, assoclen: Any =, flags: Any =) -> builtins.int
Runtime:
MISSING

The Zen of Python, by Tim Peters

Beautiful is better than ugly.
Explicit is better than implicit.
Simple is better than complex.
Complex is better than complicated.
Flat is better than nested.
Sparse is better than dense.
Readability counts.
Special cases aren't special enough to break the rules.
Although practicality beats purity.
Errors should never pass silently.
Unless explicitly silenced.
In the face of ambiguity, refuse the temptation to guess.
There should be one-- and preferably only one --obvious way to do it.
Although that way may not be obvious at first unless you're Dutch.
Now is better than never.
Although never is often better than *right* now.
If the implementation is hard to explain, it's a bad idea.
If the implementation is easy to explain, it may be a good idea.
Namespaces are one honking great idea -- let's do more of those!
note: unused whitelist entry site.getsitepackages
note: unused whitelist entry site.getuserbase
note: unused whitelist entry site.getusersitepackages

NB: stubtest output depends on the Python version it is run with. See README.md for more details.
NB: We only check positional-only arg accuracy for Python 3.8.
If stubtest is complaining about 'unused whitelist entry' after your fix, please remove the entry from the whitelist file. Note you may have to do this for other version-specific whitelists as well. Thanks for helping burn the backlog of errors!

Command run was: /home/pieter/miniconda3/envs/typeshed/bin/python -m mypy.stubtest --ignore-missing-stub --check-typeshed --custom-typeshed-dir . --whitelist tests/stubtest_whitelists/py3_common.txt --whitelist tests/stubtest_whitelists/py36.txt --ignore-positional-only

stubtest failed

@JelleZijlstra
Copy link
Member

I think that's probably just expected differences due to names being present only on some OSs; maybe @hauntsaninja can confirm.

An easier way to run the tests is to fork typeshed on GitHub and enable Travis CI on your fork.

@PGijsbers
Copy link
Contributor Author

Thank you for the help. The unit tests ran successfully on my branch in my fork, so I put up the PR.

@hauntsaninja
Copy link
Collaborator

hauntsaninja commented Feb 28, 2020

Thanks for dealing with the tests! Yeah, stubtest will pick up platform differences, in which case the whitelisted errors checked in don't match up. I'll find ways to improve this + I can document this better.

hauntsaninja pushed a commit to hauntsaninja/typeshed that referenced this issue Feb 28, 2020
Document that the test will likely fail locally, to help cases like python#3782
srittau pushed a commit that referenced this issue Feb 29, 2020
Document that the test will likely fail locally, to help cases like #3782
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants