App.extend() not type hint friendly?
See original GitHub issueThis may be an incorrect usage of App.extend() but when my CLI starts it creates an instance of a github client that gets used in a Github Cement controller:
app.extend("github", Github(access_token))
With this method of extending, I beleive you lose access for python’s type hints to be aware of what app.github
is and therefore you lose things like autocompletion in VS Code.
Possibly there is a better way to handle this use case?
Issue Analytics
- State:
- Created 3 years ago
- Comments:8 (5 by maintainers)
Top Results From Across the Web
How can I extend class parameters with a method while ...
I get no type hints from typescript when I access them using indexing, and accessing them with dot syntax is impossible, because typescript ......
Read more >Why optional type hinting in python is not that popular? - Reddit
I don't really get the arguments that it's so burdensome to add type hints. Typehints are entirely optional, and can be introduced as...
Read more >[Proposal] Type-hint what can be type-hinted #1409 - GitHub
Of course I'm not proposing to force type-hinting stuff just for ... [5.8] Fix for container app()->call() method laravel/framework#26920.
Read more >[Python-Dev] Type hints -- a mediocre programmer's reaction
I've heard this argument that, because the type hints are optional, they're not something that beginners or the average user needs to worry...
Read more >Using Python's Type Annotations - DEV Community
Type Annotating is a new feature added in PEP 484 that allows adding type hints to variables. They are used to inform someone...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Yea it looks like
self.app.*
gets lost as well. This is a screenshot from a newly generated todo tutorial app:Back in the top-level
main.py
it looks likeapp
is an instance ofMyApp
but the type system can’t figure out the handlers.Hi @derks !
As a workaround, what about casting
self.app.*
toApp
? It works when done in the controller class:Code completion works up to the first level, meaning that
app.self.*
is discovered, butapp.self.config.*
isn’t. This could be solved:app
’s attributes (eg.app.self.config
andapp.self.config.cache
) to their type, but only after these attributes have been set; orCheers, Cocco
PS: Please note that, in the screenshot, I missed a
super().__init__()
in the first line of the__init__()
method.