Python Forum
what can i uuse ... for? - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: General (https://python-forum.io/forum-1.html)
+--- Forum: News and Discussions (https://python-forum.io/forum-31.html)
+--- Thread: what can i uuse ... for? (/thread-36579.html)



what can i uuse ... for? - Skaperen - Mar-07-2022

i have a function with an argument that needs to be highly flexible. it already has various cases for ints and strings and True and False. i am wondering if i can also use ... as a caller provided value, is it safe?


RE: what can i uuse ... for? - ndc85430 - Mar-07-2022

You haven't shown any code, but it sounds like your function is quite complex if it has to handle all these different cases. Perhaps polymorphism, whether with classes, or e.g. functools.singledispatch would be a better design?


RE: what can i uuse ... for? - Gribouillis - Mar-07-2022

Syntactically, you cannot use ... where a name is expected, but the value ... or Ellipsis can be passed to a function call. It is an object like any other Python object.


RE: what can i uuse ... for? - Skaperen - Mar-07-2022

(Mar-07-2022, 07:27 AM)ndc85430 Wrote: You haven't shown any code,
the function is very large and would easily divert people off topic. there would be a lot of distracting talk about other aspects of the code.
(Mar-07-2022, 07:48 AM)Gribouillis Wrote: Syntactically, you cannot use ... where a name is expected, but the value ... or Ellipsis can be passed to a function call. It is an object like any other Python object.
i was thinking of using it as a value being passed and then in the function, checking for it like:
if foo is ...:
or:
if foo is Ellipsis:



RE: what can i uuse ... for? - ndc85430 - Mar-07-2022

That the function is very large is another sign that it does too much. Sure, it probably would obscure the important stuff to those reading on the forum. In several months, it'll also be more opaque to you. You'd benefit from the ideas in Uncle Bob's Clean Code. The "step down" rule is particularly useful.


RE: what can i uuse ... for? - Skaperen - Mar-08-2022

and the function is a "work in progress".


RE: what can i uuse ... for? - ndc85430 - Mar-08-2022

When do you refactor? If you're doing test-driven development, for example, the refactor step is right after getting the test to pass. I feel like test after doesn't give you the same kind of rhythm.


RE: what can i uuse ... for? - Skaperen - Mar-08-2022

are we changing the topic of this thread or starting a new one?