python


Python Type hinting with curses


I'm trying to figure out what to put in my type annotation at the top of this function.
I have the following trivial example:
import curses
def main(stdscr):
stdscr.clear()
stdscr.addstr(2, 0, "What is the type of stdscr?")
stdscr.addstr(5, 0, "It is: {}".format(type(stdscr)))
stdscr.refresh()
stdscr.getkey()
curses.wrapper(main)
This returns <type '_curses.curses window'>. This doesn't seem like it will work with Type hinting as it has a space in it. The expected result would be WindowObject listed in the documentation. I can't find a path to WindowObject in the curses module itself. EDIT: The documentation is incorrect here.
How do I write main with accurate type annotation?
Your problem is that the type you spect is just not the real type of the object, the method type() always tells you the type correctly, so by sure the doc. is wrong.
Unfortunately, the curses module does not appear to be fully typed within typeshed. There was some preliminary work done a few months ago, but the Windows object has not been added yet. You can check the Python 3 'curses' stubs for yourself here and here.
Currently, the stubs default to typing curses.wrapper as:
def wrapper(func, *args, **kwds): ...
...which, in turn, is equivalent to:
def wrapper(func: Callable[..., Any], *args: Any, **kwds: Any): ...
So, that means that there really is no suitable type to assign to your main functions parameter at the moment, apart from Any.
That said, if you're up for it, you might be able to contribute some stubs to complete the curses module yourself! It doesn't seem like the Window object is that terribly complex and should hopefully be relatively straightforward to type.
The main complication might be hammering out where exactly the 'Window' object should be imported from, if it doesn't exist within the curses module itself. You might perhaps want to stick the 'Windows' object within the typing module itself, just like typing.re.Pattern and typing.re.Match.

Related Links

Bokeh server callback initiated from Flask application
Python Variable Amount Of Input
Turn pandas dataframe list into boolean column
How to handle concatenate with empty matrix
python django translation .po and .mo file not translating the files
jupyter not using version set by pyenv
Generalize print+format for a variable number of inputs
What are the differences in these two codes? [closed]
What is the correct way to change image channel ordering between channels first and channels last?
Python to capture screenshot of big file
How can I compare the difference between digits of two numbers?
How to find specific list among other lists
Use variable inside open and also use find and replace in python [on hold]
Can robot framework keyword can be executed in python console?
OpenMDAO/ScipyOptimizer “UnboundLocalError: local variable 'f_new' referenced before assignment”
From C to Python passage by pointer and modification of values [closed]

Categories

HOME
cntk
jsviews
bing
angular2-routing
translation
json-ld
qpython3
javamail
azureservicebus
user
subquery
spinnaker
jpeg2000
raphael
avplayeritem
servicemix
restfb
jflex
forum
pitest
xor
spring-insight
geo
web-audio-api
data-extraction
transient
node-horseman
von-neumann
geomesa
pox
nunit-3.0
nlb
broadleaf-commerce
liquid-xml
inkscape
zero
parent
common.logging
socketscan
intellij-idea-2016
code-composer
mediawiki-extensions
productivity
median
context-free-language
dojox.grid.datagrid
aqgridview
ti-basic
bnd
react-native-fbsdk
iphone-developer-program
jszip
date-range
barcode-printing
coremidi
tomee
uwp-maps
asynccallback
magento-1.4
void
getrusage
jenkins-scriptler
hyperthreading
on-duplicate-key
shift-jis
ember-cli-addons
cpan
lexicographic
viewflipper
pgagent
cpu-speed
cppdepend
crystal-reports-10
flash-cc
db4o
mimosa
gfs
threadx
visual-studio-2003
justgage
fraud-prevention
feof
gjs
maven-ant-tasks
mysql-error-1045
tcxgrid
carbide
recordset
rtsp-client
webrat
odbc-sql-server-driver
opcodes
system-codedom-compiler
virtualquery
gears

Resources

Encrypt Message



code
soft
python
ios
c
html
jquery
cloud
mobile