mirror of
https://github.com/pocketpy/pocketpy
synced 2025-11-08 12:40:17 +00:00
Compare commits
No commits in common. "a156aaa81cc89d73b345bbbf0b5935e2ade4ea86" and "0031e87db44a9c6e0dbc96e6936f50d428ec5d07" have entirely different histories.
a156aaa81c
...
0031e87db4
@ -85,18 +85,18 @@ def dir(obj=None):
|
||||
if obj is None:
|
||||
return list(globals().keys())
|
||||
|
||||
attributes = set()
|
||||
|
||||
if not isinstance(obj, type):
|
||||
if hasattr(obj, "__dir__"):
|
||||
return sorted(obj.__dir__())
|
||||
attributes.update(dir(type(obj)))
|
||||
return obj.__dir__()
|
||||
|
||||
attributes = set()
|
||||
# Set object attributes.
|
||||
if hasattr(obj, "__dict__"):
|
||||
attributes.update(obj.__dict__.keys())
|
||||
|
||||
if hasattr(obj, "__base__") and obj.__base__ is not None:
|
||||
attributes.update(dir(obj.__base__))
|
||||
# Set type attributes.
|
||||
if not isinstance(obj, type):
|
||||
if hasattr(type(obj), "__dict__"):
|
||||
attributes.update(type(obj).__dict__.keys())
|
||||
|
||||
return sorted(attributes)
|
||||
|
||||
|
||||
@ -50,19 +50,3 @@ assert not all([False, False])
|
||||
|
||||
assert list(enumerate([1,2,3])) == [(0,1), (1,2), (2,3)]
|
||||
assert list(enumerate([1,2,3], 1)) == [(1,1), (2,2), (3,3)]
|
||||
|
||||
assert "__name__" in dir()
|
||||
|
||||
class Base:
|
||||
def inherited(): ...
|
||||
|
||||
class Test(Base):
|
||||
cls_attr = 'a'
|
||||
def __init__(self):
|
||||
self.self_attr = 1
|
||||
assert {"self_attr", "cls_attr", "inherited"}.issubset(dir(Test()))
|
||||
|
||||
class CustomDir:
|
||||
def __dir__(self):
|
||||
return ["custom"]
|
||||
assert ["custom"] == dir(CustomDir())
|
||||
Loading…
x
Reference in New Issue
Block a user