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

Can't open certain csv files using pandas while being written with pandas - CParserError
Layered Architecture TypeError: 'module' object is not callable
How to scrape the HTML content of a webpage after rendering is completed in Python [duplicate]
parsing in korea's web site of naver
uwsgi http is ambiguous
Minimizing a function in python
pandas pivot table, creating table by taking difference of multiple columns
Python selenium use the same window instead of having 3 pop up?
Install Python 3 alongside Python 2 problematic?
Delete some elements from numpy array
ElasticSearch throwing mapper parsing exception when indexing JSON array of integers and strings
Using one PhantomJS browser for each worker rather than creating new instance for each URL in queue slows performance dramatically
Extract OneToOne Field in django model
In python solve for a matrix with restrictions
Setting up the EB CLI - error nonetype get_frozen_credentials
Saving a csv with excel so python can append rows correctly

Categories

HOME
python
google-apps-script
jsf
cil
websphere
facebook-graph-api
user
apiconnect
ng-admin
onenote-api
uiactivityviewcontroller
wysiwyg
gatsby
xlsx
phoenix
squarespace
react-leaflet
spring-cloud-config
yeoman-generator
google-api-java-client
jogl
attask
jquery-form-validator
avplayeritem
bootstrap-typeahead
pipelinedb
opencart2.3
ab-initio
mangodb
websauna
vegan
jackson-dataformat-csv
oracle-xml-db
spreedly
transient
viewstate
pox
swagger-editor
android-download-manager
floating-accuracy
bayesian-networks
microdata
lftp
azure-availability-set
uiviewpropertyanimator
amazon-machine-learning
istorage
chrome-remote-desktop
modelattribute
static-code-analysis
laravel-query-builder
sql-import-wizard
cjson
spring-ioc
pydio
gitweb
pax-web
mercurial-hook
dbscan
emokit
twgl.js
altbeacon
except
license-key
plone-3.x
mysqldumpslow
twitter-rest-api
stackframe
chaining
start-job
java-melody
temp-tables
scala-2.11
dmp
dache
codeigniter-a3m
map-force
broadcasting
uipickerviewcontroller
openkinect
internal
gamepad
sql-server-2012-web
trimming
stagefright
haskell-platform
google-closure-library
pep8
abnf
ubuntu-11.10
fotoware
ninject-extensions
isolatedstorage
concurrent-programming
cross-domain-policy
nemerle
ihttphandler
junit3
drawtext
mvccontrib-grid
hibernate3-maven-plugin
hadoop-plugins
project-lifecycle

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