forked from goodboy/tractor
1
0
Fork 0

`NamespacePath._mk_fqnp()` handle `__mod__` for methods

Need to use `__self__.__mod__` in the method case i guess..
runtime_to_msgspec
Tyler Goodlet 2024-04-18 15:10:23 -04:00
parent 77a15ebf19
commit 7372404d76
1 changed files with 12 additions and 7 deletions

View File

@ -76,9 +76,11 @@ class NamespacePath(str):
return self._ref return self._ref
@staticmethod @staticmethod
def _mk_fqnp(ref: type | object) -> tuple[str, str]: def _mk_fqnp(
ref: type|object,
) -> tuple[str, str]:
''' '''
Generate a minial ``str`` pair which describes a python Generate a minial `str` pair which describes a python
object's namespace path and object/type name. object's namespace path and object/type name.
In more precise terms something like: In more precise terms something like:
@ -87,10 +89,9 @@ class NamespacePath(str):
of THIS type XD of THIS type XD
''' '''
if ( if isfunction(ref):
isfunction(ref)
):
name: str = getattr(ref, '__name__') name: str = getattr(ref, '__name__')
mod_name: str = ref.__module__
elif ismethod(ref): elif ismethod(ref):
# build out the path manually i guess..? # build out the path manually i guess..?
@ -99,15 +100,19 @@ class NamespacePath(str):
type(ref.__self__).__name__, type(ref.__self__).__name__,
ref.__func__.__name__, ref.__func__.__name__,
]) ])
mod_name: str = ref.__self__.__module__
else: # object or other? else: # object or other?
# isinstance(ref, object) # isinstance(ref, object)
# and not isfunction(ref) # and not isfunction(ref)
name: str = type(ref).__name__ name: str = type(ref).__name__
mod_name: str = ref.__module__
# TODO: return static value direactly?
#
# fully qualified namespace path, tuple. # fully qualified namespace path, tuple.
fqnp: tuple[str, str] = ( fqnp: tuple[str, str] = (
ref.__module__, mod_name,
name, name,
) )
return fqnp return fqnp
@ -115,7 +120,7 @@ class NamespacePath(str):
@classmethod @classmethod
def from_ref( def from_ref(
cls, cls,
ref: type | object, ref: type|object,
) -> NamespacePath: ) -> NamespacePath: