Skip to content
This repository has been archived by the owner on Jan 2, 2025. It is now read-only.

Commit

Permalink
♻️ Restore while maintaining docs integrity
Browse files Browse the repository at this point in the history
  • Loading branch information
falexwolf committed Jul 16, 2024
1 parent 1c3d18d commit 4600930
Showing 1 changed file with 26 additions and 20 deletions.
46 changes: 26 additions & 20 deletions lnschema_core/models.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import annotations

import builtins
from datetime import datetime
from typing import (
TYPE_CHECKING,
Expand Down Expand Up @@ -53,6 +54,7 @@


_TRACKING_READY: bool | None = None
IS_RUN_FROM_IPYTHON = getattr(builtins, "__IPYTHON__", False)


class IsVersioned(models.Model):
Expand Down Expand Up @@ -494,26 +496,30 @@ def __new__(cls, name, bases, attrs, **kwargs):
# used in VSCode
# this only solves the problem for Jupyter Editors
#
# def __dir__(cls):
# # this is needed to bring auto-complete on the class-level back
# # https://laminlabs.slack.com/archives/C04FPE8V01W/p1717535625268849
# # Filter class attributes, excluding instance methods
# result = [
# attr
# for attr in cls.__dict__.keys()
# if not attr.startswith("__")
# and not (
# callable(cls.__dict__[attr])
# and not isinstance(
# cls.__dict__[attr], (classmethod, staticmethod, type)
# )
# )
# ]
# # Add non-dunder attributes from RegistryMeta
# for attr in dir(RegistryMeta):
# if not attr.startswith("__") and attr not in result:
# result.append(attr)
# return result
def __dir__(cls):
# this is needed to bring auto-complete on the class-level back
# https://laminlabs.slack.com/archives/C04FPE8V01W/p1717535625268849
# Filter class attributes, excluding instance methods

exclude_instance_methods = IS_RUN_FROM_IPYTHON

def include_attribute(attr_name, attr_value):
if attr_name.startswith("__"):
return False
if exclude_instance_methods and callable(attr_value):
return isinstance(attr_value, (classmethod, staticmethod, type))
return True

result = [
attr_name
for attr_name, attr_value in cls.__dict__.items()
if include_attribute(attr_name, attr_value)
]
# Add non-dunder attributes from RegistryMeta
for attr in dir(RegistryMeta):
if not attr.startswith("__") and attr not in result:
result.append(attr)
return result

def from_values(
cls,
Expand Down

0 comments on commit 4600930

Please sign in to comment.