get_args
See original GitHub issueIs it possible to use typing_inspect
to achieve the following?
from typing import Any, List, TypeVar
import typing_inspect
class C:
x: int
def __init__(self, x: int) -> None:
self.x = x
T = TypeVar("T")
class L(List[T]):
def append_new(self, *args: Any, **kw: Any) -> T:
item_class = ???(T)
self.append(item_class(*args, **kw))
return self[-1]
l = L[C]()
print(l.append_new(42).x)
Issue Analytics
- State:
- Created 4 years ago
- Comments:11 (1 by maintainers)
Top Results From Across the Web
getArgs - Hoogle - Haskell.org
Computation getArgs returns a list of the program's command line arguments (not including the program name), as ByteStrings. Unlike getArgs, this function ...
Read more >How does getArgs work? - haskell - Stack Overflow
getArgs gives you the arguments you supplied at the command line when you ran the program. If you don't supply any arguments at...
Read more >Haskell : getArgs - ZVON.org
Computation getArgs returns a list of the program's command line arguments (not including the program name). Related: getProgName. Example 1. Program: import ...
Read more >getArgs() - IBM
The getArgs() method returns a table that contains one row for each argument that will be accepted by the UDX. In the database,...
Read more >getargs - Rust - Docs.rs
getargs is a low-level, efficient and versatile argument parser that works similarly to getopts . It works by producing a stream of options,...
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
This is as the arguments are on the base class. Using
get_generic_bases
works fine.It should be noted that this is hacky solution, and may give unexpected results if the class is
class C(Mapping[int, T], Sequence[str])
. The behavior can be seen in one oftyping_inspect_lib.get_mro_orig
tests. This function isn’t available until #31 has been completed.Using this should be fairly simple when it does come out: (Note: untested and subject to change)
It should be noted that this won’t return
(int, T, str)
if used onC
, in an equivalent way. It however is rather simple to change it to return this, return a combination ofMapping
andSequence
.It doesn’t look like this is at all possible to do in the constructor, in Python 3.7.2 at least.
This is as
typing_inspect.get_generic_type(self)
returns<class '__main__.L'>
not__main__.L[int, str]
.Otherwise it looks rather simple: