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

Fix doc #2556

Merged
merged 2 commits into from
Sep 11, 2024
Merged

Fix doc #2556

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion astroid/nodes/node_classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -2061,7 +2061,16 @@ def __init__(
:param end_col_offset: The end column this node appears on in the
source code. Note: This is after the last symbol.
"""
self.value: Any = value
if getattr(value, "__name__", None) == "__doc__":
warnings.warn( # pragma: no cover
"You have most likely called a __doc__ field of some object "
"and it didn't return a string. "
"That happens to some symbols from the standard library. "
"Check for isinstance(<X>.__doc__, str).",
RuntimeWarning,
stacklevel=0,
)
self.value = value
"""The value that the constant represents."""

self.kind: str | None = kind # can be None
Expand Down
2 changes: 1 addition & 1 deletion astroid/nodes/scoped_nodes/scoped_nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -1624,7 +1624,7 @@ def infer_call_result(
col_offset=0,
end_lineno=0,
end_col_offset=0,
parent=self,
parent=AstroidManager().adhoc_module,
)
new_class.hide = True
new_class.postinit(
Expand Down
15 changes: 7 additions & 8 deletions astroid/raw_building.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ def _add_dunder_class(func, member) -> None:
if not cls_name:
return
cls_bases = [ancestor.__name__ for ancestor in python_cls.__bases__]
ast_klass = build_class(cls_name, cls_bases, python_cls.__doc__)
doc = python_cls.__doc__ if isinstance(python_cls.__doc__, str) else None
ast_klass = build_class(cls_name, cls_bases, doc)
func.instance_attrs["__class__"] = [ast_klass]


Expand Down Expand Up @@ -316,7 +317,7 @@ def object_build_function(
args,
posonlyargs,
defaults,
member.__doc__,
member.__doc__ if isinstance(member.__doc__, str) else None,
kwonlyargs=kwonlyargs,
kwonlydefaults=kwonly_defaults,
)
Expand Down Expand Up @@ -357,11 +358,8 @@ def _base_class_object_build(
"""
class_name = name or getattr(member, "__name__", None) or localname
assert isinstance(class_name, str)
klass = build_class(
class_name,
basenames,
member.__doc__,
)
doc = member.__doc__ if isinstance(member.__doc__, str) else None
klass = build_class(class_name, basenames, doc)
klass._newstyle = isinstance(member, type)
node.add_local_node(klass, localname)
try:
Expand Down Expand Up @@ -718,11 +716,12 @@ def _astroid_bootstrapping() -> None:
parent=nodes.Unknown(),
)
klass.parent = astroid_builtin
doc = _type.__doc__ if isinstance(_type.__doc__, str) else None
klass.postinit(
bases=[],
body=[],
decorators=None,
doc_node=nodes.Const(value=_type.__doc__) if _type.__doc__ else None,
doc_node=nodes.Const(doc) if doc else None,
)
builder.object_build(klass, _type)
astroid_builtin[_type.__name__] = klass
Expand Down
Loading