Skip to content

Commit

Permalink
Improve operator type naming
Browse files Browse the repository at this point in the history
  • Loading branch information
vxgmichel committed May 8, 2024
1 parent 63e1881 commit 6ea0de7
Showing 1 changed file with 34 additions and 15 deletions.
49 changes: 34 additions & 15 deletions aiostream/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -369,9 +369,6 @@ async def random(offset=0., width=1.):

# Gather attributes
class OperatorImplementation:
__qualname__ = name
__module__ = module
__doc__ = doc

original = staticmethod(original_func)

Expand Down Expand Up @@ -411,8 +408,18 @@ def __str__(self) -> str:
OperatorImplementation.__call__.__module__ = module
OperatorImplementation.__call__.__doc__ = doc

# Create operator class
return OperatorImplementation()
# Create operator singleton
properly_named_class = type(
name,
(OperatorImplementation,),
{
"__qualname__": name,
"__module__": module,
"__doc__": doc,
},
)
operator_instance = properly_named_class()
return operator_instance


def pipable_operator(
Expand Down Expand Up @@ -507,9 +514,6 @@ def double(source):

# Gather attributes
class PipableOperatorImplementation:
__qualname__ = name
__module__ = module
__doc__ = doc

original = staticmethod(original_func)

Expand Down Expand Up @@ -582,8 +586,17 @@ def __str__(self) -> str:
if extra_doc:
PipableOperatorImplementation.pipe.__doc__ += "\n\n " + extra_doc

# Create operator class
operator_instance = PipableOperatorImplementation()
# Create operator singleton
properly_named_class = type(
name,
(PipableOperatorImplementation,),
{
"__qualname__": name,
"__module__": module,
"__doc__": doc,
},
)
operator_instance = properly_named_class()
return operator_instance


Expand Down Expand Up @@ -674,9 +687,6 @@ def chain_twice(*sources):

# Gather attributes
class SourcesOperatorImplementation:
__qualname__ = name
__module__ = module
__doc__ = doc

original = staticmethod(original_func)

Expand Down Expand Up @@ -741,6 +751,15 @@ def __str__(self) -> str:
if extra_doc:
SourcesOperatorImplementation.pipe.__doc__ += "\n\n " + extra_doc

# Create operator class
operator_instance = SourcesOperatorImplementation()
# Create operator singleton
properly_named_class = type(
name,
(SourcesOperatorImplementation,),
{
"__qualname__": name,
"__module__": module,
"__doc__": doc,
},
)
operator_instance = properly_named_class()
return operator_instance

0 comments on commit 6ea0de7

Please sign in to comment.