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

Scraping g2a[dot]com with BeautifulSoup
Can't find a specific link using Beautiful Soup in Python
Issue when trying to install scipy in virtualenv on rpi
Python List Comprehension how-to
Django returns 404 after using restframework into existing project
How to add the second line of labels in matplotlib plot
Join dataframes - one with multiindex columns and the other without
How to set up multiple frames
Create a python programm standalone on windows 7 [duplicate]
Execute python script on remote server from another script
Passing a variable between two methods in Python?
What is the best way to add custom methods into generated protoc classes for Python?
Retain edit data for one form when submitting a second
Associating string representations with a Python Enum that uses integer values
python3 for win and cygwin - line endings in buffer
How invert the result used the method sort

Categories

HOME
symfony
shopify
vb6
jsviews
mapping
warnings
boost-thread
agile
transparent
rfc
propertygrid
docker-windows
avl-tree
codeblocks
aruco
facebook-javascript-sdk
window
keystore
xlsx
public-key-encryption
gwtp
multiple-monitors
spring-cloud-config
medium-editor
apache-karaf
redux-observable
nsmenuitem
csh
samsung-mobile
python-textprocessing
kong
image-quality
dss
dd-wrt
svnkit
apache-cloudstack
graph-databases
stocks
spreedly
polymorphism
swiftcharts
pycparser
body-parser
remote-server
pace
oscommerce
vmd
mongoexport
nsexception
knockout-3.0
html-agility-pack
taskmanager
walmart-electrode
dimple.js
jgraph
tcserver
mcrypt
gce
opencpu
date-range
inject
spring-ioc
nofollow
contour
selecteditem
group-concat
altbeacon
acm
test-class
self-hosting
android-viewholder
enyo
mirrorlink
mysqldumpslow
retro-computing
js-cookie
lexicographic
alphablending
cloudpebble
grunt-contrib-concat
facebook-wall
system.web
yahoo-boss-api
mfmailcomposeviewcontroll
alertifyjs
json-patch
db4o
bsod
pyjade
windows-mobile-6
lame
client-library
template-haskell
vt100
tfs-power-tools
getusermedia
file-exists
flash-cs5.5
msgbox
hinstance
paintcomponent
phpcrawl
aio
opcodes
system-codedom-compiler
castle-validators
outlook-form
msf

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App