Comments (9)
I can't say I like the name get_typing
, but in general I think it makes sense to provide some extra functionality. I would say even some tricky things related to #6. It looks like some basic functionality (like get_origin()
) will get into typing
itself in Python 3.8, so we can focus on more "advanced" introspection functionality here.
Would you be interested in merging our efforts?
In general I think this may be a good idea. What is your (more detailed) plan for this?
from typing_inspect.
About get_last_origin
and get_last_args
this was inspired by how things used to work, I agree they may be not very useful for users of "modern" typing
.
from typing_inspect.
@ilevkivskyi I'm not too sure what better name to use.
My, rather simple, plan is:
-
Which functions from my library would you want/not want? Would you want any of these to replace your current functions? (These work in 2.7, 3.4+ and 3.5.0+)
get_typing
. (As described aboveget_origin
+get_extra
)get_args
get_parameters
get_type_info
(Returns a named tuple of the above three functions output)get_type_var_info
(Returns a named tuple of the type vars information)get_bases
get_mro
get_mro_orig
I also have
build_types
to make an OOP interface, but after making the above I've found it to be obsolete. And so I don't think adding this would helptyping_inspect
. -
I'll remove
build_types
from my library and tests. -
After deciding what functions you want, and what we should name them. I'll fork your version adding what code and tests we want from my code into yours.
Also:
-
Is Python 3.5.0 support wanted / unwanted?
If it's wanted, I'll make it so your current tests don't run in 3.5.0-3.5.2.
I also think adding support for your functions to 3.5.0-2 should be added separately from adding my code. -
Is ensuring compatibility between Python versions wanted/unwanted?
-
I have tried to ensure whatever is passed to a function has the same result in all Python versions. (Within reason,
mro
for example shouldn't return the same in Python 2.7 as 3.7 due to changes incollections.abc
) -
In Python 3.5.0 to 3.5.2 I change the return type in all of my functions so the 'class type' of say
typing.Dict
isn'tabc.MutableMapping
but insteaddict
. -
The function
get_mro
changes the results in versions below Python 3.7 so that they only return the class types. It also gets the mro from not the type provided, but its class type. (RemovingGeneric
from the mro)This means if you pass
typing.Mapping
it'll convert it toabc.Mapping
and then get the mro, as I couldn't find the mro on 'typing types' in Python 3.7.
-
Would you want these too?
from typing_inspect.
Sorry for long silence, I went vacation for couple weeks and then it took time to be back on track.
Would you want any of these to replace your current functions?
I want to keep all current functions so that we maintain full backwards compatibility with previous versions of typing_inspect
. I am however fine with adding all new functions that add some new functionality.
Is Python 3.5.0 support wanted / unwanted?
It is wanted, but not very important.
Is ensuring compatibility between Python versions wanted/unwanted?
Yes, this is wanted and important (except in some cases where it reflects some crucial changes in typing
, but these are quite rare).
from typing_inspect.
I'll only include new functions publicly, these functions require the duplicate functions to work and so I'll hide them in a sub package, typing_inspect.v2
. This will result in duplicate code, but ensure backwards compatibility.
I should be able to start looking into the PR next week.
from typing_inspect.
so I'll hide them in a sub package
I would rather chose a name like typing_inspect.extras
for the subpackage.
from typing_inspect.
@ilevkivskyi Unfortunately this is taking longer than expected. I've been focusing on improving typing_inspect_lib's code quality, currently through linters and coverage.py, which is at ~97%. Only the documentation seems to be lacking significantly now.
I'm unsure what your docstrings conform to, and can't find anything in your configuration files to test against. I'm planning on using pydocstyle and vanilla Sphinx to help ensure that they at least somewhat resemble yours. Is this the correct environment?
from typing_inspect.
I'm unsure what your docstrings conform to, and can't find anything in your configuration files to test against. I'm planning on using pydocstyle and vanilla Sphinx to help ensure that they at least somewhat resemble yours. Is this the correct environment?
I don't have any docstring style enforcement. I just try to follow some basic guidelines in PEP 257. But if you want you can try adding a linter for this.
from typing_inspect.
One function I needed and implemented is get_type_arguments
: I want that if I have a base class:
class Base(typing.Generic[A, B, C]):
If I do:
class Foo(Base[float, int, string]):
I can call get_type_arguments(Foo)
and get back a dict of {A: float, B: int, C: string}
.
The issue is only that I want to call it inside __init__
, but in Python 3.7 and later this is not possible without stack walking hack.
from typing_inspect.
Related Issues (20)
- is_literal broken with new typing_extensions HOT 3
- get_origin gives inconsistent results for differently defined Unions HOT 3
- `is_generic_type(List)` is False in 3.9 HOT 6
- Add Final type
- get_origin(Dict) returns None in python 3.9 HOT 1
- Support Python 3.9 HOT 4
- Add a simple is_type(t) method HOT 2
- 0.6.0: test suite is failing HOT 3
- Python 3.9 support breaks List HOT 2
- ImportError on typing_extensions HOT 1
- Fix for Python 3.9.0/1 does not work with typing_extensions 3.7.4. HOT 1
- `typing_inspect.get_args` `Annotated` metadata args HOT 1
- test_typed_dict_typing_extension fails with typing_extensions==4.1.1 HOT 3
- New release? HOT 2
- `get_origin()` doesn't support PEP 585 generic types? HOT 2
- Breaks `marshmallow_dataclass.NewType` HOT 4
- `get_parameters` throws exception with non-indexed types from `typing` on python 3.10 HOT 1
- `typed_dict_keys` fails to return data on 3.10 HOT 1
- BUG: is_union_type return None sometime HOT 2
- `get_parameters` failed for Tuple HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from typing_inspect.