-
Notifications
You must be signed in to change notification settings - Fork 55
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ENH
trusting np.ufuncs and np.dtypes
#336
Changes from 9 commits
89561a0
22b0043
3fc5116
3ad5f78
06f4bb9
71818db
dae61fb
98661be
abc5ceb
f9e1cba
bc2099c
e0e951f
fb69a45
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ | |
import sys | ||
from dataclasses import dataclass, field | ||
from functools import singledispatch | ||
from types import ModuleType | ||
from typing import Any, Type | ||
from zipfile import ZipFile | ||
|
||
|
@@ -200,3 +201,36 @@ def get_type_paths(types: Any) -> list[str]: | |
types = [types] | ||
|
||
return [get_type_name(t) if not isinstance(t, str) else t for t in types] | ||
|
||
|
||
def get_public_type_names(module: ModuleType, oftype: Type) -> list[str]: | ||
""" | ||
Helper function that gets the type names of all | ||
public objects of the given ``_type`` from the given ``module``, | ||
adrinjalali marked this conversation as resolved.
Show resolved
Hide resolved
|
||
which start with the root module name. | ||
|
||
Public objects are those that can be read via ``dir(...)``. | ||
|
||
Parameters | ||
---------- | ||
module: ModuleType | ||
Module under which the public objects are defined. | ||
oftype: Type | ||
The type of the objects. | ||
|
||
Returns | ||
---------- | ||
type_names_list: list of str | ||
The sorted list of type names, all as strings, | ||
e.g. ``["numpy.core._multiarray_umath.absolute"]``. | ||
""" | ||
module_name, _, _ = module.__name__.rpartition(".") | ||
|
||
return sorted( | ||
{ | ||
type_name | ||
for attr in dir(module) | ||
if (issubclass((obj := getattr(module, attr)).__class__, oftype)) | ||
and ((type_name := get_type_name(obj)).startswith(module_name)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For both lines, are the outer parens necessary? It seems to me that they could be removed. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. wasn't easy to use walrus operator in such "complex" statement 😄 Thanks for the catch - removed them! |
||
} | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of sending users on a chase, let's just clear the confusion right away: That this is not only responsible for np arrays, but also for np generics.