Skip to content
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

Missing import datetime & numpy #89

Closed
OlivierLDff opened this issue Dec 4, 2022 · 1 comment
Closed

Missing import datetime & numpy #89

OlivierLDff opened this issue Dec 4, 2022 · 1 comment

Comments

@OlivierLDff
Copy link

Hi, in generated stub

  • there is a missing import datatime when using chrono
  • there is a missing import numpy when using eigen

I guess fix should go somewhere in

def to_lines(self): # type: () -> List[str]
result = []
if self.doc_string:
result += ['"""' + self.doc_string.replace('"""', r"\"\"\"") + '"""']
if sys.version_info[:2] >= (3, 7):
result += ["from __future__ import annotations"]
result += ["import {}".format(self.module.__name__)]
# import everything from typing
result += ["import typing"]
for name, class_ in self.imported_classes.items():
class_name = getattr(class_, "__qualname__", class_.__name__)
if name == class_name:
suffix = ""
else:
suffix = " as {}".format(name)
result += [
"from {} import {}{}".format(class_.__module__, class_name, suffix)
]
# import used packages
used_modules = sorted(self.get_involved_modules_names())
if used_modules:
# result.append("if TYPE_CHECKING:")
# result.extend(map(self.indent, map(lambda m: "import {}".format(m), used_modules)))
result.extend(map(lambda mod: "import {}".format(mod), used_modules))
if "numpy" in used_modules and not BARE_NUPMY_NDARRAY:
result += ["_Shape = typing.Tuple[int, ...]"]
# add space between imports and rest of module
result += [""]
globals_ = {}
exec("from {} import *".format(self.module.__name__), globals_)
all_ = set(member for member in globals_.keys() if member.isidentifier()) - {
"__builtins__"
}
result.append(
"__all__ = [\n "
+ ",\n ".join(map(lambda s: '"%s"' % s, sorted(all_)))
+ "\n]\n\n"
)
for x in itertools.chain(self.classes, self.free_functions, self.attributes):
result.extend(x.to_lines())
result.append("") # Newline at EOF
return result

Is is a problem in my library that i forgot to specify something?

Have a nice day, thanks for the library helping me everyday!

@sizmailov
Copy link
Owner

Hi! Thanks for the report!

All the import issues should be resolved with #112

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants