+ 1

Documenting Python Function With a Socket Parameter - Python

i have a function that takes a socket connection as a parameter. i always document my functions with the 'docstring' for good practice and to make it nice and clear. now, i got to this problem: i type: :type conn: socket # conn is the socket connection of type socket and later in that function i get a warning where i did: conn.close() warning msg: "parameter 'fd' unfilled" How to fix it? i know that it gets an integer, what to put in there? 0? 1? what to do?

29th Aug 2021, 12:44 PM
Yahel
Yahel - avatar
2 Answers
+ 1
Your question is a bit confusing. Are you asking what to write in the docstring, or how to fix the warning? fd is a file descriptor, which is associated with the socket. Check this post, it can lead you to many related resources: https://stackoverflow.com/questions/62768793/socket-closefd-in-JUMP_LINK__&&__python__&&__JUMP_LINK-what-does-fd-mean#62768848 I don't know the solution, or even why you get the warning. Maybe the version of Python you are using, can have an effect on this. Just some ideas. There is a fileno() method in socket library which should return the file descriptor id. Python doc mentions that you can call shutdown() before close(). The close() has two variants, one on the package level (that requires a file descriptor) and another on the object level, where the fd should be known by the object itself. Maybe you are using the wrong one? Cannot tell without seeing your code.
31st Aug 2021, 4:17 AM
Tibor Santa
Tibor Santa - avatar
0
Tibor Santa, when there is no docstring, there is no warning... i know that you need to close a socket like so: conn.close(). it always works.. but when i type that the conn object is of type 'socket', it wants me to write an integer to the close(fd=some_integer). what should i type there? i also have a simillar problem with another library - sqlite3... what should i write in the docstring in order to make python know what object should it receive? (when i tell it that the object is of type sqlite3.cursor it doesnt recognize it)
31st Aug 2021, 1:10 PM
Yahel
Yahel - avatar