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

Generate a csv file partly based on user input with python
How can I write input on new lines in files in python, without adding an empty line?
python reading sql db encoding error at /python2.7/json/encoder.py
Base64 decode to pdf on Windows OS with python
Partial parameters are duplicated
accessing nested element in HTML by CLASS_NAME using selenium
Where is the cfnbootstrap folder?
Want requests.get to wait for redirection during some time
How to run a program by being activated in another program in python
Django: what is the purpose of “$” symbol in urlpatterns?
Installed the google-cloud-storage module 0.22.0, Imports fine by itself but not as an import of an import
replace double quotes with '\"' in python
How to replace sublists within a list?
How to listen for an AUDIO file using Python and Selenium Webdriver
Storing Encrypted Data On A MySQL Database with Python, Pandas and SQLAlchemy [Connection Lost]
How to make python decorators work like a tag to make function calls “by tag”

Categories

HOME
paypal
dotnetrdf
redis
tinyos
system-verilog
google-sheets-api
couchdb-2.0
ll
iis-7.5
user
sudo
onenote-api
deeplearning4j
google-plus
criteria
hosts
rfid
wordpress-theming
mongodb-query
postmessage
rhapsody
internet-explorer-8
flexlm
cruisecontrol.net
os161
nsmenuitem
explode
pdfsharp
compare-and-swap
helper
pcre
autofill
clockwork
pljson
phpspreadsheet
sonarqube-scan
mongoexport
s3cmd
restful-url
xbim
crop
broadcast
mouseclick-event
component-pascal
chrome-remote-desktop
volume
laravel-query-builder
barcode-printing
inject
cleditor
rmongodb
dts
pax-web
metalsmith
codesign
elastix
picking
mpeg-4
usb-drive
magento-1.4
spservices
throughput
textkit
base32
uptodate
hg-git
jython-2.7
multipleselection
ctrlp
viewflipper
named-ranges
ibmsbt
method-overriding
bullet
picat
unison
help-viewer
xenocode
facebook-chat
cdata
sslexception
stagefright
windows-update
backbone-relational
surveyor-gem
domain-calculus
ubuntu-11.10
plone-funnelweb
flash-cs5.5
emacs23
wchar
fileutils
datamember
windows-live-id
hadoop-plugins
scatterview
usability-testing

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